diff --git a/src/navigation.rs b/src/navigation.rs index 477eb76..b9a9ed8 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, error::Error, fmt::Debug, hash::Hash, marker::Ph use bevy::prelude::*; use bevy_input_actionmap::InputMap; -use bevy_rapier2d::prelude::*; +use bevy_rapier2d::{na::UnitComplex, prelude::*}; use bevy_tts::Tts; use derive_more::{Deref, DerefMut}; @@ -85,7 +85,7 @@ fn movement_controls( &mut Speed, &MaxSpeed, Option<&RotationSpeed>, - &mut Transform, + &mut RigidBodyPosition, Option<&Destination>, ), With, @@ -95,7 +95,7 @@ fn movement_controls( S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash, A: Hash + Eq + Clone + Send + Sync, { - for (entity, mut velocity, mut speed, max_speed, rotation_speed, mut transform, destination) in + for (entity, mut velocity, mut speed, max_speed, rotation_speed, mut position, destination) in query.iter_mut() { let sprinting = if let Some(action) = config.action_sprint.clone() { @@ -108,7 +108,7 @@ fn movement_controls( } else { commands.entity(entity).remove::(); } - let mut direction = Vec3::default(); + let mut direction = Vec2::default(); if let Some(action) = config.action_forward.clone() { if input.active(action) { direction.x += 1.; @@ -136,10 +136,10 @@ fn movement_controls( ) { let delta = rotation_speed.radians() * time.delta_seconds(); if input.active(rotate_left) { - transform.rotate(Quat::from_rotation_z(delta)); + position.position.rotation *= UnitComplex::new(delta); } if input.active(rotate_right) { - transform.rotate(Quat::from_rotation_z(-delta)); + position.position.rotation *= UnitComplex::new(-delta); } } if direction.length_squared() != 0. { @@ -183,12 +183,14 @@ fn movement_controls( **max_speed / config.sprint_movement_factor }; **speed = s; - direction = transform.compute_matrix().transform_vector3(direction); - let mut v = Vec2::new(direction.x, direction.y) * **speed; if let Some(strength) = strength { - v *= strength; + direction *= strength; } - velocity.linvel = v.into(); + //direction = transform.compute_matrix().transform_vector3(direction); + let mut v: Vector = (direction * **speed).into(); + v = position.position.rotation.transform_vector(&v); + velocity.linvel = v; + //velocity.linvel = position.position.rotation.transform_vector(&velocity.linvel); } else if destination.is_none() { velocity.linvel = Vec2::ZERO.into(); **speed = 0.;