Make snap turns more reliable, and avoid queuing unnecessary direction removal.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0a38e65d26
commit
43b163fbd9
|
@ -58,7 +58,7 @@ struct SnapTimer(Timer);
|
|||
|
||||
impl Default for SnapTimer {
|
||||
fn default() -> Self {
|
||||
Self(Timer::from_seconds(0.25, false))
|
||||
Self(Timer::from_seconds(0.2, false))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,8 +171,9 @@ fn snap(
|
|||
>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
for (entity, actions, mut transform, mut velocity, direction) in query.iter_mut() {
|
||||
if actions.just_pressed(NavigationAction::SnapLeft) {
|
||||
println!("snap left");
|
||||
if snap_timers.contains_key(&entity) {
|
||||
continue;
|
||||
} else if actions.pressed(NavigationAction::SnapLeft) {
|
||||
snap_timers.insert(entity, SnapTimer::default());
|
||||
transform.rotation = Quat::from_rotation_z(match direction {
|
||||
CardinalDirection::North => PI,
|
||||
|
@ -181,9 +182,7 @@ fn snap(
|
|||
CardinalDirection::West => -PI / 2.,
|
||||
});
|
||||
velocity.angvel = 0.;
|
||||
}
|
||||
if actions.just_pressed(NavigationAction::SnapRight) {
|
||||
println!("Snap right");
|
||||
} else if actions.pressed(NavigationAction::SnapRight) {
|
||||
snap_timers.insert(entity, SnapTimer::default());
|
||||
transform.rotation = Quat::from_rotation_z(match direction {
|
||||
CardinalDirection::North => 0.,
|
||||
|
@ -192,18 +191,15 @@ fn snap(
|
|||
CardinalDirection::West => PI / 2.,
|
||||
});
|
||||
velocity.angvel = 0.;
|
||||
}
|
||||
if actions.just_pressed(NavigationAction::SnapCardinal) {
|
||||
} else if actions.pressed(NavigationAction::SnapReverse) {
|
||||
snap_timers.insert(entity, SnapTimer::default());
|
||||
transform.rotate(Quat::from_rotation_z(PI));
|
||||
velocity.angvel = 0.;
|
||||
} else if actions.pressed(NavigationAction::SnapCardinal) {
|
||||
let yaw: Angle = direction.into();
|
||||
let yaw = yaw.radians();
|
||||
transform.rotation = Quat::from_rotation_z(yaw);
|
||||
velocity.angvel = 0.;
|
||||
tts.speak(direction.to_string(), true)?;
|
||||
}
|
||||
if actions.just_pressed(NavigationAction::SnapReverse) {
|
||||
snap_timers.insert(entity, SnapTimer::default());
|
||||
transform.rotate(Quat::from_rotation_z(PI));
|
||||
velocity.angvel = 0.;
|
||||
}
|
||||
}
|
||||
|
@ -237,11 +233,17 @@ fn update_direction(
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_direction(mut commands: Commands, removed: RemovedComponents<Transform>) {
|
||||
fn remove_direction(
|
||||
mut commands: Commands,
|
||||
removed: RemovedComponents<Transform>,
|
||||
directions: Query<&CardinalDirection>,
|
||||
) {
|
||||
for entity in removed.iter() {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.remove::<CardinalDirection>();
|
||||
});
|
||||
if directions.contains(entity) {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.remove::<CardinalDirection>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user