can use shoot pose
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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::<TriggerStateRes>();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ pub struct CharacterAnimations {
|
||||
pub idle: AnimationNodeIndex,
|
||||
pub run: AnimationNodeIndex,
|
||||
pub jump: AnimationNodeIndex,
|
||||
pub shooting: Option<AnimationNodeIndex>,
|
||||
pub graph: Handle<AnimationGraph>,
|
||||
}
|
||||
|
||||
@@ -148,18 +149,29 @@ fn setup_once_loaded(
|
||||
.map(|(name, animation)| (name.to_string(), animation.clone()))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
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(),
|
||||
};
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<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 deadzone = 0.2;
|
||||
|
||||
@@ -74,6 +78,10 @@ fn set_movement_flag(mut player_movement: ResMut<PlayerMovement>, 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(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user