set animation flags independant of controller

This commit is contained in:
2025-07-03 17:16:07 +02:00
parent 6bfdcf37fc
commit 132db8dbe8
3 changed files with 55 additions and 45 deletions

View File

@@ -1,11 +1,10 @@
use super::{ControlState, ControllerSet, Controls};
use super::{ControlState, ControllerSet};
use crate::{
GameState,
abilities::TriggerStateRes,
animation::AnimationFlags,
character::HasCharacterAnimations,
control::{controller_common::MovementSpeedFactor, controls::ControllerSettings},
player::{Player, PlayerBodyMesh},
player::PlayerBodyMesh,
};
use bevy::prelude::*;
use happy_feet::prelude::{Grounding, KinematicVelocity, MoveInput};
@@ -16,7 +15,7 @@ impl Plugin for CharacterControllerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
PreUpdate,
(set_animation_flags, rotate_view, apply_controls)
(rotate_view, apply_controls)
.chain()
.in_set(ControllerSet::ApplyControlsRun)
.run_if(in_state(GameState::Playing)),
@@ -24,42 +23,6 @@ impl Plugin for CharacterControllerPlugin {
}
}
/// Sets the movement flag, which is an indicator for the rig animation and the braking system.
fn set_animation_flags(
mut flags: Query<&mut AnimationFlags>,
controls: Res<Controls>,
trigger: Res<TriggerStateRes>,
player: Single<(&Grounding, &HasCharacterAnimations), With<Player>>,
) {
let mut direction = controls.keyboard_state.move_dir;
let deadzone = 0.2;
let (grounding, has_anims) = *player;
let mut flags = flags.get_mut(*has_anims.collection()).unwrap();
if let Some(gamepad) = controls.gamepad_state {
direction += gamepad.move_dir;
}
if flags.any_direction {
if direction.length_squared() < deadzone {
flags.any_direction = false;
}
} else if direction.length_squared() > deadzone {
flags.any_direction = true;
}
if flags.shooting != trigger.is_active() {
flags.shooting = trigger.is_active();
}
// `apply_controls` sets the jump flag when the player actually jumps.
// Unset the flag on hitting the ground
if grounding.is_grounded() {
flags.jumping = false;
}
}
fn rotate_view(
controls: Res<ControlState>,
mut player: Query<&mut Transform, With<PlayerBodyMesh>>,