Closed idanarye closed 1 year ago
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:
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.
When leaving the crouch button under an obstacle, the character gets stack:
https://github.com/idanarye/bevy-tnua/assets/1149255/f0887f93-f398-471b-b3b3-37c088530a4e
Pressing the crouch button again allows moving, but it would be nice if this was avoidable.