Clear angular velocity when snapping.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Nolan Darilek 2022-03-21 22:06:09 -05:00
parent 4357a5838a
commit 52d8e8db3b

View File

@ -222,7 +222,14 @@ fn snap<S, A: 'static>(
input: Res<InputMap<A>>, input: Res<InputMap<A>>,
config: Res<NavigationConfig<S, A>>, config: Res<NavigationConfig<S, A>>,
mut snapping: ResMut<Snapping>, mut snapping: ResMut<Snapping>,
mut position: Query<(&mut RigidBodyPositionComponent, &CardinalDirection), With<Player>>, mut query: Query<
(
&mut RigidBodyPositionComponent,
&mut RigidBodyVelocityComponent,
&CardinalDirection,
),
With<Player>,
>,
) -> Result<(), Box<dyn Error>> ) -> Result<(), Box<dyn Error>>
where where
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash, S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
@ -230,7 +237,7 @@ where
{ {
if let Some(action) = config.action_snap_left.clone() { if let Some(action) = config.action_snap_left.clone() {
if input.just_active(action) { if input.just_active(action) {
for (mut position, direction) in position.iter_mut() { for (mut position, mut velocity, direction) in query.iter_mut() {
**snapping = true; **snapping = true;
position.position.rotation = UnitComplex::new(match direction { position.position.rotation = UnitComplex::new(match direction {
CardinalDirection::North => PI, CardinalDirection::North => PI,
@ -238,12 +245,13 @@ where
CardinalDirection::South => 0., CardinalDirection::South => 0.,
CardinalDirection::West => PI * 1.5, CardinalDirection::West => PI * 1.5,
}); });
velocity.angvel = 0.;
} }
} }
} }
if let Some(action) = config.action_snap_right.clone() { if let Some(action) = config.action_snap_right.clone() {
if input.just_active(action) { if input.just_active(action) {
for (mut position, direction) in position.iter_mut() { for (mut position, mut velocity, direction) in query.iter_mut() {
**snapping = true; **snapping = true;
position.position.rotation = UnitComplex::new(match direction { position.position.rotation = UnitComplex::new(match direction {
CardinalDirection::North => 0., CardinalDirection::North => 0.,
@ -251,25 +259,28 @@ where
CardinalDirection::South => PI, CardinalDirection::South => PI,
CardinalDirection::West => PI / 2., CardinalDirection::West => PI / 2.,
}); });
velocity.angvel = 0.;
} }
} }
} }
if let Some(action) = config.action_snap_cardinal.clone() { if let Some(action) = config.action_snap_cardinal.clone() {
if input.just_active(action) { if input.just_active(action) {
for (mut position, direction) in position.iter_mut() { for (mut position, mut velocity, direction) in query.iter_mut() {
**snapping = true; **snapping = true;
let yaw: Angle = direction.into(); let yaw: Angle = direction.into();
let yaw = yaw.radians(); let yaw = yaw.radians();
position.position.rotation = UnitComplex::new(yaw); position.position.rotation = UnitComplex::new(yaw);
velocity.angvel = 0.;
tts.speak(direction.to_string(), true)?; tts.speak(direction.to_string(), true)?;
} }
} }
} }
if let Some(action) = config.action_snap_reverse.clone() { if let Some(action) = config.action_snap_reverse.clone() {
if input.just_active(action) { if input.just_active(action) {
for (mut position, _) in position.iter_mut() { for (mut position, mut velocity, _) in query.iter_mut() {
**snapping = true; **snapping = true;
position.position.rotation *= UnitComplex::new(PI); position.position.rotation *= UnitComplex::new(PI);
velocity.angvel = 0.;
} }
} }
} }