Basic rotation works.
This commit is contained in:
parent
ac728cc864
commit
99b6da1953
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, error::Error, fmt::Debug, hash::Hash, marker::Ph
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_input_actionmap::InputMap;
|
use bevy_input_actionmap::InputMap;
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::{na::UnitComplex, prelude::*};
|
||||||
use bevy_tts::Tts;
|
use bevy_tts::Tts;
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ fn movement_controls<S, A: 'static>(
|
||||||
&mut Speed,
|
&mut Speed,
|
||||||
&MaxSpeed,
|
&MaxSpeed,
|
||||||
Option<&RotationSpeed>,
|
Option<&RotationSpeed>,
|
||||||
&mut Transform,
|
&mut RigidBodyPosition,
|
||||||
Option<&Destination>,
|
Option<&Destination>,
|
||||||
),
|
),
|
||||||
With<Player>,
|
With<Player>,
|
||||||
|
@ -95,7 +95,7 @@ fn movement_controls<S, A: 'static>(
|
||||||
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
||||||
A: Hash + Eq + Clone + Send + Sync,
|
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()
|
query.iter_mut()
|
||||||
{
|
{
|
||||||
let sprinting = if let Some(action) = config.action_sprint.clone() {
|
let sprinting = if let Some(action) = config.action_sprint.clone() {
|
||||||
|
@ -108,7 +108,7 @@ fn movement_controls<S, A: 'static>(
|
||||||
} else {
|
} else {
|
||||||
commands.entity(entity).remove::<Sprinting>();
|
commands.entity(entity).remove::<Sprinting>();
|
||||||
}
|
}
|
||||||
let mut direction = Vec3::default();
|
let mut direction = Vec2::default();
|
||||||
if let Some(action) = config.action_forward.clone() {
|
if let Some(action) = config.action_forward.clone() {
|
||||||
if input.active(action) {
|
if input.active(action) {
|
||||||
direction.x += 1.;
|
direction.x += 1.;
|
||||||
|
@ -136,10 +136,10 @@ fn movement_controls<S, A: 'static>(
|
||||||
) {
|
) {
|
||||||
let delta = rotation_speed.radians() * time.delta_seconds();
|
let delta = rotation_speed.radians() * time.delta_seconds();
|
||||||
if input.active(rotate_left) {
|
if input.active(rotate_left) {
|
||||||
transform.rotate(Quat::from_rotation_z(delta));
|
position.position.rotation *= UnitComplex::new(delta);
|
||||||
}
|
}
|
||||||
if input.active(rotate_right) {
|
if input.active(rotate_right) {
|
||||||
transform.rotate(Quat::from_rotation_z(-delta));
|
position.position.rotation *= UnitComplex::new(-delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if direction.length_squared() != 0. {
|
if direction.length_squared() != 0. {
|
||||||
|
@ -183,12 +183,14 @@ fn movement_controls<S, A: 'static>(
|
||||||
**max_speed / config.sprint_movement_factor
|
**max_speed / config.sprint_movement_factor
|
||||||
};
|
};
|
||||||
**speed = s;
|
**speed = s;
|
||||||
direction = transform.compute_matrix().transform_vector3(direction);
|
|
||||||
let mut v = Vec2::new(direction.x, direction.y) * **speed;
|
|
||||||
if let Some(strength) = strength {
|
if let Some(strength) = strength {
|
||||||
v *= strength;
|
direction *= strength;
|
||||||
}
|
}
|
||||||
velocity.linvel = v.into();
|
//direction = transform.compute_matrix().transform_vector3(direction);
|
||||||
|
let mut v: Vector<Real> = (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() {
|
} else if destination.is_none() {
|
||||||
velocity.linvel = Vec2::ZERO.into();
|
velocity.linvel = Vec2::ZERO.into();
|
||||||
**speed = 0.;
|
**speed = 0.;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user