idanarye / bevy-tnua

A floating character controller for Bevy

Home Page:https://crates.io/crates/bevy-tnua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trying to stand when the character crawls under an obstacle get it stuck

idanarye opened this issue · comments

When leaving the crouch button under an obstacle, the character gets stack:

Peek.2023-05-16.16-18.mp4

Pressing the crouch button again allows moving, but it would be nice if this was avoidable.

Looks like the spring force is enough to glue the character to the ceiling. It doesn't happen in the 2D example because the spring is much weaker there (it doesn't have a character with legs, so I figured it's okay to use a weaker spring)

Ideally I should cast a ray upward to determine if the character has enough room to stand, but I worry about how to create that second ray Bevy-wise. My options are:

  1. Add another component for an upward proximity sensor. This can be a bit tricky because every physics backend is going to have to support all the proximity sensor components. I can probably use generics here, but still...
  2. Make the proximity sensor a vector or a hashmap.
  3. Make a child entity for the upward pointing proximity sensor. Basically:
    #[derive(Component)]
    struct TnuaRoofDetector {
        proximity_sensor_entity: Entity,
        cant_stand_up: bool,
        // other fields?
    }
    
    fn roof_detector_update_system(
        mut query: Query<Entity, &TnuaRoofDetector>,
        mut proximity_sensors_query: Query<&TnuaProximitySensor>,
        mut commands: Command,
    ) {
        for (entity, mut roof_detector) in query.iter_mut() {
            if let Ok(proximity_sensor) = proximity_sensors_query.get_single(roof_detector.proximity_sensor_entity) {
                roof_detector.cant_stand_up = ...;
            } else {
                commands.entity(entity).with_children(|commands| {
                    roof_detector.proximity_sensor_entity = commands.spawn(...);
                })
            }
        }
    }
    Creating new entities on the fly, though, is not something I'm that fond of since it tends to mess with other things (I'm probably worried about Yoleck - though in Yoleck's case the problem I'm worried about can be solved with a simple is_in_editor check)

There is also the option to just let the user do it on their own, but I rather avoid that. Also, having multiple proximity sensors can be good if I want to implement things like vehicles in the future.