diff --git a/assets/models/characters/angry demonstrator.glb b/assets/models/characters/angry demonstrator.glb index 7a9e93d..0d40ad5 100644 Binary files a/assets/models/characters/angry demonstrator.glb and b/assets/models/characters/angry demonstrator.glb differ diff --git a/assets/models/characters/commando.glb b/assets/models/characters/commando.glb index aca8de8..cdbe438 100644 Binary files a/assets/models/characters/commando.glb and b/assets/models/characters/commando.glb differ diff --git a/assets/models/characters/legionnaire.glb b/assets/models/characters/legionnaire.glb index 9005f95..582afb8 100644 Binary files a/assets/models/characters/legionnaire.glb and b/assets/models/characters/legionnaire.glb differ diff --git a/src/abilities/mod.rs b/src/abilities/mod.rs index 019eb32..e5705e2 100644 --- a/src/abilities/mod.rs +++ b/src/abilities/mod.rs @@ -81,11 +81,17 @@ pub struct TriggerThrow(pub TriggerData); pub struct TriggerMissile(pub TriggerData); #[derive(Resource, Default)] -struct TriggerStateRes { +pub struct TriggerStateRes { cooldown: f32, active: bool, } +impl TriggerStateRes { + pub fn is_active(&self) -> bool { + self.active + } +} + pub fn plugin(app: &mut App) { app.init_resource::(); diff --git a/src/character.rs b/src/character.rs index 9bac759..ac946ff 100644 --- a/src/character.rs +++ b/src/character.rs @@ -35,6 +35,7 @@ pub struct CharacterAnimations { pub idle: AnimationNodeIndex, pub run: AnimationNodeIndex, pub jump: AnimationNodeIndex, + pub shooting: Option, pub graph: Handle, } @@ -148,18 +149,29 @@ fn setup_once_loaded( .map(|(name, animation)| (name.to_string(), animation.clone())) .collect::>(); - let (graph, node_indices) = AnimationGraph::from_clips([ + let mut clips = vec![ animations["idle"].clone(), animations["run"].clone(), animations["jump"].clone(), - ]); + ]; - // // Insert a resource with the current scene information + if let Some(shooting_animation) = animations.get("shoot") { + clips.push(shooting_animation.clone()); + } + + let (graph, node_indices) = AnimationGraph::from_clips(clips); + + // Insert a resource with the current scene information let graph_handle = graphs.add(graph); let animations = CharacterAnimations { idle: node_indices[0], run: node_indices[1], jump: node_indices[2], + shooting: if node_indices.len() == 4 { + Some(node_indices[3]) + } else { + None + }, graph: graph_handle.clone(), }; diff --git a/src/control/controller_common.rs b/src/control/controller_common.rs index 6403a82..7650d69 100644 --- a/src/control/controller_common.rs +++ b/src/control/controller_common.rs @@ -53,6 +53,7 @@ pub fn reset_upon_switch( #[derive(Resource, Default)] pub struct PlayerMovement { pub any_direction: bool, + pub shooting: bool, } /// A marker component indicating that an entity is using a character controller. diff --git a/src/control/controller_running.rs b/src/control/controller_running.rs index 9ce8d0c..90c04f1 100644 --- a/src/control/controller_running.rs +++ b/src/control/controller_running.rs @@ -1,5 +1,5 @@ use super::{ControlState, ControllerSet, Controls, controller_common::MovementSpeedFactor}; -use crate::{GameState, player::PlayerBodyMesh}; +use crate::{GameState, abilities::TriggerStateRes, player::PlayerBodyMesh}; use avian3d::{math::*, prelude::*}; use bevy::{ecs::query::Has, prelude::*}; @@ -59,7 +59,11 @@ fn update_grounded( } /// Sets the movement flag, which is an indicator for the rig animation and the braking system. -fn set_movement_flag(mut player_movement: ResMut, controls: Res) { +fn set_movement_flag( + mut player_movement: ResMut, + controls: Res, + trigger: Res, +) { let mut direction = controls.keyboard_state.move_dir; let deadzone = 0.2; @@ -74,6 +78,10 @@ fn set_movement_flag(mut player_movement: ResMut, controls: Res< } else if direction.length_squared() > deadzone { player_movement.any_direction = true; } + + if player_movement.shooting != trigger.is_active() { + player_movement.shooting = trigger.is_active(); + } } fn rotate_view( diff --git a/src/player.rs b/src/player.rs index 7af0635..0a99042 100644 --- a/src/player.rs +++ b/src/player.rs @@ -20,7 +20,6 @@ use bevy::{ prelude::*, window::{CursorGrabMode, PrimaryWindow}, }; - use std::time::Duration; #[derive(Component, Default)] @@ -181,9 +180,21 @@ fn toggle_animation( animations.idle }; - transition - .play(&mut player, index, Duration::from_millis(100)) - .repeat(); + let (mut index, mut duration) = (index, Duration::from_millis(100)); + + if movement.shooting { + if let Some(shoot_anim) = animations.shooting { + (index, duration) = (shoot_anim, Duration::from_millis(10)); + } + } + + if transition + .get_main_animation() + .map(|playing| playing != index) + .unwrap_or_default() + { + transition.play(&mut player, index, duration).repeat(); + } } } }