Added strafe-like rolling

This commit is contained in:
Joshua Barretto 2023-10-12 12:34:08 +01:00
parent ad580ab33c
commit d5565c4a41
5 changed files with 35 additions and 3 deletions

View File

@ -2404,6 +2404,7 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState {
timer: Duration::default(), timer: Duration::default(),
stage_section: StageSection::Buildup, stage_section: StageSection::Buildup,
was_wielded: false, // false by default. utils might set it to true was_wielded: false, // false by default. utils might set it to true
prev_aimed_dir: None,
is_sneaking: false, is_sneaking: false,
was_combo: None, was_combo: None,
}), }),

View File

@ -9,6 +9,7 @@ use crate::{
behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*, utils::*,
}, },
util::Dir,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;
@ -41,6 +42,8 @@ pub struct Data {
pub stage_section: StageSection, pub stage_section: StageSection,
/// Had weapon /// Had weapon
pub was_wielded: bool, pub was_wielded: bool,
/// What direction were we previously aiming in?
pub prev_aimed_dir: Option<Dir>,
/// Is sneaking, true if previous state was also considered sneaking /// Is sneaking, true if previous state was also considered sneaking
pub is_sneaking: bool, pub is_sneaking: bool,
/// Was in state with combo /// Was in state with combo

View File

@ -1246,6 +1246,9 @@ fn handle_ability(
roll.is_sneaking = true; roll.is_sneaking = true;
} }
} }
if data.character.is_aimed() {
roll.prev_aimed_dir = Some(data.controller.inputs.look_dir);
}
} }
return true; return true;
} }
@ -1553,6 +1556,11 @@ pub fn end_ability(data: &JoinData<'_>, update: &mut StateUpdate) {
time_entered: *data.time, time_entered: *data.time,
}); });
} }
if let CharacterState::Roll(roll) = data.character {
if let Some(dir) = roll.prev_aimed_dir {
update.ori = dir.into();
}
}
} }
pub fn end_melee_ability(data: &JoinData<'_>, update: &mut StateUpdate) { pub fn end_melee_ability(data: &JoinData<'_>, update: &mut StateUpdate) {

View File

@ -5,6 +5,7 @@ use super::{
use common::{ use common::{
comp::item::{Hands, ToolKind}, comp::item::{Hands, ToolKind},
states::utils::StageSection, states::utils::StageSection,
util::Dir,
}; };
use std::f32::consts::PI; use std::f32::consts::PI;
@ -19,6 +20,7 @@ type RollAnimationDependency = (
Vec3<f32>, Vec3<f32>,
f32, f32,
Option<StageSection>, Option<StageSection>,
Option<Dir>,
); );
impl Animation for RollAnimation { impl Animation for RollAnimation {
@ -41,6 +43,7 @@ impl Animation for RollAnimation {
last_ori, last_ori,
_global_time, _global_time,
stage_section, stage_section,
prev_aimed_dir,
): Self::Dependency<'_>, ): Self::Dependency<'_>,
anim_time: f32, anim_time: f32,
rate: &mut f32, rate: &mut f32,
@ -257,9 +260,25 @@ impl Animation for RollAnimation {
next.foot_r.orientation = Quaternion::rotation_x(0.9 * movement1); next.foot_r.orientation = Quaternion::rotation_x(0.9 * movement1);
next.torso.position = Vec3::new(0.0, 0.0, 7.0 * movement1); next.torso.position = Vec3::new(0.0, 0.0, 7.0 * movement1);
next.torso.orientation = let roll_spin = Quaternion::rotation_x(-0.3 + movement1 * -0.4 + movement2 * -2.0 * PI);
Quaternion::rotation_x(-0.3 + movement1 * -0.4 + movement2 * -2.0 * PI) next.torso.orientation = if let Some(prev_aimed_dir) = prev_aimed_dir {
* Quaternion::rotation_z(tilt * -10.0); // This is *slightly* hacky. Because rolling is not strafed movement, we
// actually correct for the entity orientation to make sure that our
// rolling motion is correct with respect to our original orientation
let move_dir = Quaternion::<f32>::from_vec4(
Dir::new(orientation.into_array().into())
.rotation()
.into_vec4()
.into_array()
.into(),
);
let aim_dir = Quaternion::<f32>::from_vec4(
prev_aimed_dir.rotation().into_vec4().into_array().into(),
);
roll_spin * move_dir.inverse() * aim_dir
} else {
roll_spin * Quaternion::rotation_z(tilt * -10.0)
};
next next
} }

View File

@ -1263,6 +1263,7 @@ impl FigureMgr {
state.last_ori * anim::vek::Vec3::<f32>::unit_y(), state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time, time,
Some(s.stage_section), Some(s.stage_section),
s.prev_aimed_dir,
), ),
stage_progress, stage_progress,
&mut state_animation_rate, &mut state_animation_rate,