can use shoot pose

This commit is contained in:
2025-05-10 00:19:58 +02:00
parent 07c4c43b6c
commit 334eacfd1c
8 changed files with 48 additions and 10 deletions

View File

@@ -81,11 +81,17 @@ pub struct TriggerThrow(pub TriggerData);
pub struct TriggerMissile(pub TriggerData); pub struct TriggerMissile(pub TriggerData);
#[derive(Resource, Default)] #[derive(Resource, Default)]
struct TriggerStateRes { pub struct TriggerStateRes {
cooldown: f32, cooldown: f32,
active: bool, active: bool,
} }
impl TriggerStateRes {
pub fn is_active(&self) -> bool {
self.active
}
}
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {
app.init_resource::<TriggerStateRes>(); app.init_resource::<TriggerStateRes>();

View File

@@ -35,6 +35,7 @@ pub struct CharacterAnimations {
pub idle: AnimationNodeIndex, pub idle: AnimationNodeIndex,
pub run: AnimationNodeIndex, pub run: AnimationNodeIndex,
pub jump: AnimationNodeIndex, pub jump: AnimationNodeIndex,
pub shooting: Option<AnimationNodeIndex>,
pub graph: Handle<AnimationGraph>, pub graph: Handle<AnimationGraph>,
} }
@@ -148,18 +149,29 @@ fn setup_once_loaded(
.map(|(name, animation)| (name.to_string(), animation.clone())) .map(|(name, animation)| (name.to_string(), animation.clone()))
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
let (graph, node_indices) = AnimationGraph::from_clips([ let mut clips = vec![
animations["idle"].clone(), animations["idle"].clone(),
animations["run"].clone(), animations["run"].clone(),
animations["jump"].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 graph_handle = graphs.add(graph);
let animations = CharacterAnimations { let animations = CharacterAnimations {
idle: node_indices[0], idle: node_indices[0],
run: node_indices[1], run: node_indices[1],
jump: node_indices[2], jump: node_indices[2],
shooting: if node_indices.len() == 4 {
Some(node_indices[3])
} else {
None
},
graph: graph_handle.clone(), graph: graph_handle.clone(),
}; };

View File

@@ -53,6 +53,7 @@ pub fn reset_upon_switch(
#[derive(Resource, Default)] #[derive(Resource, Default)]
pub struct PlayerMovement { pub struct PlayerMovement {
pub any_direction: bool, pub any_direction: bool,
pub shooting: bool,
} }
/// A marker component indicating that an entity is using a character controller. /// A marker component indicating that an entity is using a character controller.

View File

@@ -1,5 +1,5 @@
use super::{ControlState, ControllerSet, Controls, controller_common::MovementSpeedFactor}; 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 avian3d::{math::*, prelude::*};
use bevy::{ecs::query::Has, 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. /// 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>, controls: Res<Controls>) { fn set_movement_flag(
mut player_movement: ResMut<PlayerMovement>,
controls: Res<Controls>,
trigger: Res<TriggerStateRes>,
) {
let mut direction = controls.keyboard_state.move_dir; let mut direction = controls.keyboard_state.move_dir;
let deadzone = 0.2; let deadzone = 0.2;
@@ -74,6 +78,10 @@ fn set_movement_flag(mut player_movement: ResMut<PlayerMovement>, controls: Res<
} else if direction.length_squared() > deadzone { } else if direction.length_squared() > deadzone {
player_movement.any_direction = true; player_movement.any_direction = true;
} }
if player_movement.shooting != trigger.is_active() {
player_movement.shooting = trigger.is_active();
}
} }
fn rotate_view( fn rotate_view(

View File

@@ -20,7 +20,6 @@ use bevy::{
prelude::*, prelude::*,
window::{CursorGrabMode, PrimaryWindow}, window::{CursorGrabMode, PrimaryWindow},
}; };
use std::time::Duration; use std::time::Duration;
#[derive(Component, Default)] #[derive(Component, Default)]
@@ -181,9 +180,21 @@ fn toggle_animation(
animations.idle animations.idle
}; };
transition let (mut index, mut duration) = (index, Duration::from_millis(100));
.play(&mut player, index, Duration::from_millis(100))
.repeat(); 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();
}
} }
} }
} }