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(),
stage_section: StageSection::Buildup,
was_wielded: false, // false by default. utils might set it to true
prev_aimed_dir: None,
is_sneaking: false,
was_combo: None,
}),

View File

@ -9,6 +9,7 @@ use crate::{
behavior::{CharacterBehavior, JoinData},
utils::*,
},
util::Dir,
};
use serde::{Deserialize, Serialize};
use std::time::Duration;
@ -41,6 +42,8 @@ pub struct Data {
pub stage_section: StageSection,
/// Had weapon
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
pub is_sneaking: bool,
/// Was in state with combo

View File

@ -1246,6 +1246,9 @@ fn handle_ability(
roll.is_sneaking = true;
}
}
if data.character.is_aimed() {
roll.prev_aimed_dir = Some(data.controller.inputs.look_dir);
}
}
return true;
}
@ -1553,6 +1556,11 @@ pub fn end_ability(data: &JoinData<'_>, update: &mut StateUpdate) {
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) {

View File

@ -5,6 +5,7 @@ use super::{
use common::{
comp::item::{Hands, ToolKind},
states::utils::StageSection,
util::Dir,
};
use std::f32::consts::PI;
@ -19,6 +20,7 @@ type RollAnimationDependency = (
Vec3<f32>,
f32,
Option<StageSection>,
Option<Dir>,
);
impl Animation for RollAnimation {
@ -41,6 +43,7 @@ impl Animation for RollAnimation {
last_ori,
_global_time,
stage_section,
prev_aimed_dir,
): Self::Dependency<'_>,
anim_time: f32,
rate: &mut f32,
@ -257,9 +260,25 @@ impl Animation for RollAnimation {
next.foot_r.orientation = Quaternion::rotation_x(0.9 * movement1);
next.torso.position = Vec3::new(0.0, 0.0, 7.0 * movement1);
next.torso.orientation =
Quaternion::rotation_x(-0.3 + movement1 * -0.4 + movement2 * -2.0 * PI)
* Quaternion::rotation_z(tilt * -10.0);
let roll_spin = Quaternion::rotation_x(-0.3 + movement1 * -0.4 + movement2 * -2.0 * PI);
next.torso.orientation = if let Some(prev_aimed_dir) = prev_aimed_dir {
// 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
}

View File

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