cleanup mig pilot and fix running idle animation

This commit is contained in:
2025-05-03 20:43:27 +02:00
parent 7274416661
commit 25cd3356b6
2 changed files with 6 additions and 26 deletions

View File

@@ -6,8 +6,8 @@ use bevy::prelude::*;
use crate::player::PlayerBodyMesh;
use super::{
ControlState, ControllerSet, Controls,
controller_common::{JumpImpulse, MovementDampingFactor, MovementSpeed, PlayerMovement},
ControlState, ControllerSet,
controller_common::{MovementDampingFactor, MovementSpeed},
};
pub struct CharacterControllerPlugin;
@@ -16,23 +16,13 @@ impl Plugin for CharacterControllerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(
set_movement_flag,
rotate_rig,
movement,
apply_movement_damping,
)
(rotate_rig, movement, apply_movement_damping)
.chain()
.in_set(ControllerSet::ApplyControlsFly), // todo only in GameState::Playing?
);
}
}
/// Sets the movement flag, which is an indicator for the rig animation and the braking system.
fn set_movement_flag(mut player_movement: ResMut<PlayerMovement>) {
player_movement.any_direction = true;
}
fn rotate_rig(
mut rig_transform_q: Option<Single<&mut Transform, With<PlayerBodyMesh>>>,
controls: Res<ControlState>,
@@ -68,18 +58,12 @@ fn rotate_rig(
/// Responds to [`MovementAction`] events and moves character controllers accordingly.
fn movement(
controls: Res<Controls>,
mut controllers: Query<(&MovementSpeed, &JumpImpulse, &mut LinearVelocity)>,
mut controllers: Query<(&MovementSpeed, &mut LinearVelocity)>,
rig_transform_q: Option<Single<&GlobalTransform, With<PlayerBodyMesh>>>,
) {
let move_dir = Vec2::new(0.0, 1.0); // Always full-throttle forwards when flying
let mut jump_requested = controls.keyboard_state.jump;
let move_dir = Vec2::new(0.0, 0.8); // Always full-throttle forwards when flying
if let Some(gamepad) = controls.gamepad_state {
jump_requested |= gamepad.jump;
}
for (movement_acceleration, jump_impulse, mut linear_velocity) in &mut controllers {
for (movement_acceleration, mut linear_velocity) in &mut controllers {
let mut direction = move_dir.extend(0.0).xzy();
if let Some(ref rig_transform) = rig_transform_q {
@@ -88,10 +72,6 @@ fn movement(
}
linear_velocity.0 = -direction * movement_acceleration.0;
if jump_requested {
linear_velocity.y = jump_impulse.0;
}
}
}