More accurately sync speed and velocity.
This commit is contained in:
parent
ef55419bb7
commit
7e6fd923a3
|
@ -297,6 +297,15 @@ fn speak_direction(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_speed(mut commands: Commands, query: Query<Entity, (Added<Speed>, Without<Velocity>)>) {
|
||||||
|
for entity in query.iter() {
|
||||||
|
commands.entity(entity).insert(Velocity {
|
||||||
|
linvel: Vec2::ZERO,
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut Velocity>) {
|
fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut Velocity>) {
|
||||||
for entity in removed.iter() {
|
for entity in removed.iter() {
|
||||||
if let Ok(mut velocity) = query.get_mut(entity) {
|
if let Ok(mut velocity) = query.get_mut(entity) {
|
||||||
|
@ -377,6 +386,7 @@ where
|
||||||
.register_type::<Sprinting>()
|
.register_type::<Sprinting>()
|
||||||
.add_system(update_direction)
|
.add_system(update_direction)
|
||||||
.add_system(speak_direction.chain(error_handler))
|
.add_system(speak_direction.chain(error_handler))
|
||||||
|
.add_system(add_speed)
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, remove_speed);
|
.add_system_to_stage(CoreStage::PostUpdate, remove_speed);
|
||||||
const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS";
|
const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS";
|
||||||
if config.movement_control_states.is_empty() {
|
if config.movement_control_states.is_empty() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user