set animation flags independant of controller
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
/*07*/(key:"green grocer", ability:Curver, range:60, ammo:10, damage:25, projectile:"carrot"),
|
/*07*/(key:"green grocer", ability:Curver, range:60, ammo:10, damage:25, projectile:"carrot"),
|
||||||
/*08*/(key:"highland hammer thrower", ability:Thrown, aps:2, ammo:10, damage:25, range:80, projectile:"hammer", interrupt_shoot:false),
|
/*08*/(key:"highland hammer thrower", ability:Thrown, aps:2, ammo:10, damage:25, range:80, projectile:"hammer", interrupt_shoot:false),
|
||||||
/*09*/(key:"legionnaire", ability:Gun, aps:2, ammo:25, range:60, damage:13, shoot_offset:0.1667),
|
/*09*/(key:"legionnaire", ability:Gun, aps:2, ammo:25, range:60, damage:13, shoot_offset:0.1667),
|
||||||
/*10*/(key:"mig pilot", ability:Missile, ammo:5, range:60, damage:100, controls:Plane),
|
/*10*/(key:"mig pilot", ability:Missile, ammo:5, range:60, damage:100, controls:Plane, interrupt_shoot:false),
|
||||||
/*11*/(key:"nanny", ability:Thrown, range:60),
|
/*11*/(key:"nanny", ability:Thrown, range:60),
|
||||||
/*12*/(key:"panic attack", ability:Turbo),
|
/*12*/(key:"panic attack", ability:Turbo),
|
||||||
/*13*/(key:"salty sea dog", ability:Boat),
|
/*13*/(key:"salty sea dog", ability:Boat),
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use super::{ControllerSet, ControllerSwitchEvent};
|
use super::{ControllerSet, ControllerSwitchEvent};
|
||||||
use crate::{
|
use crate::{
|
||||||
GameState,
|
GameState,
|
||||||
control::{SelectedController, controls::ControllerSettings},
|
abilities::TriggerStateRes,
|
||||||
|
animation::AnimationFlags,
|
||||||
|
character::HasCharacterAnimations,
|
||||||
|
control::{Controls, SelectedController, controls::ControllerSettings},
|
||||||
heads_database::HeadControls,
|
heads_database::HeadControls,
|
||||||
player::PlayerBodyMesh,
|
player::{Player, PlayerBodyMesh},
|
||||||
};
|
};
|
||||||
use avian3d::{math::*, prelude::*};
|
use avian3d::{math::*, prelude::*};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
@@ -27,13 +30,57 @@ pub fn plugin(app: &mut App) {
|
|||||||
.run_if(in_state(GameState::Playing))
|
.run_if(in_state(GameState::Playing))
|
||||||
.before(ControllerSet::ApplyControlsRun)
|
.before(ControllerSet::ApplyControlsRun)
|
||||||
.before(ControllerSet::ApplyControlsFly),
|
.before(ControllerSet::ApplyControlsFly),
|
||||||
)
|
);
|
||||||
.add_systems(
|
|
||||||
|
app.add_systems(
|
||||||
|
PreUpdate,
|
||||||
|
set_animation_flags
|
||||||
|
.run_if(in_state(GameState::Playing))
|
||||||
|
.after(ControllerSet::ApplyControlsRun)
|
||||||
|
.after(ControllerSet::ApplyControlsFly),
|
||||||
|
);
|
||||||
|
|
||||||
|
app.add_systems(
|
||||||
FixedPreUpdate,
|
FixedPreUpdate,
|
||||||
decelerate.run_if(in_state(GameState::Playing)),
|
decelerate.run_if(in_state(GameState::Playing)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Reset the pitch and velocity of the character if the controller was switched.
|
/// Reset the pitch and velocity of the character if the controller was switched.
|
||||||
pub fn reset_upon_switch(
|
pub fn reset_upon_switch(
|
||||||
mut c: Commands,
|
mut c: Commands,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use super::{ControlState, ControllerSet, Controls};
|
use super::{ControlState, ControllerSet};
|
||||||
use crate::{
|
use crate::{
|
||||||
GameState,
|
GameState,
|
||||||
abilities::TriggerStateRes,
|
|
||||||
animation::AnimationFlags,
|
animation::AnimationFlags,
|
||||||
character::HasCharacterAnimations,
|
character::HasCharacterAnimations,
|
||||||
control::{controller_common::MovementSpeedFactor, controls::ControllerSettings},
|
control::{controller_common::MovementSpeedFactor, controls::ControllerSettings},
|
||||||
player::{Player, PlayerBodyMesh},
|
player::PlayerBodyMesh,
|
||||||
};
|
};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use happy_feet::prelude::{Grounding, KinematicVelocity, MoveInput};
|
use happy_feet::prelude::{Grounding, KinematicVelocity, MoveInput};
|
||||||
@@ -16,7 +15,7 @@ impl Plugin for CharacterControllerPlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
(set_animation_flags, rotate_view, apply_controls)
|
(rotate_view, apply_controls)
|
||||||
.chain()
|
.chain()
|
||||||
.in_set(ControllerSet::ApplyControlsRun)
|
.in_set(ControllerSet::ApplyControlsRun)
|
||||||
.run_if(in_state(GameState::Playing)),
|
.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(
|
fn rotate_view(
|
||||||
controls: Res<ControlState>,
|
controls: Res<ControlState>,
|
||||||
mut player: Query<&mut Transform, With<PlayerBodyMesh>>,
|
mut player: Query<&mut Transform, With<PlayerBodyMesh>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user