Fixed footstep timings

This commit is contained in:
Joshua Barretto 2023-10-12 20:31:10 +01:00
parent 245855bf5c
commit 0b1ffb6695
7 changed files with 54 additions and 43 deletions

View File

@ -150,7 +150,7 @@
"voxygen.audio.sfx.footsteps.stepdirt_4",
"voxygen.audio.sfx.footsteps.stepdirt_5",
],
threshold: 1.8,
threshold: 0.5,
subtitle: "subtitle-footsteps_earth",
),
QuadRun(Earth): (
@ -161,7 +161,7 @@
"voxygen.audio.sfx.footsteps.stepdirt_4",
"voxygen.audio.sfx.footsteps.stepdirt_5",
],
threshold: 0.9,
threshold: 0.25,
subtitle: "subtitle-footsteps_earth",
),
Run(Grass): (
@ -173,7 +173,7 @@
"voxygen.audio.sfx.footsteps.stepgrass_5",
"voxygen.audio.sfx.footsteps.stepgrass_6",
],
threshold: 1.8,
threshold: 1.0,
subtitle: "subtitle-footsteps_grass",
),
QuadRun(Grass): (
@ -185,7 +185,7 @@
"voxygen.audio.sfx.footsteps.stepgrass_5",
"voxygen.audio.sfx.footsteps.stepgrass_6",
],
threshold: 0.9,
threshold: 0.5,
subtitle: "subtitle-footsteps_grass",
),
// For when sand 1) exists and 2) has unique sounds
@ -215,7 +215,7 @@
"voxygen.audio.sfx.footsteps.snow_step_2",
"voxygen.audio.sfx.footsteps.snow_step_3",
],
threshold: 1.8,
threshold: 1.0,
subtitle: "subtitle-footsteps_snow",
),
QuadRun(Snow): (
@ -224,7 +224,7 @@
"voxygen.audio.sfx.footsteps.snow_step_2",
"voxygen.audio.sfx.footsteps.snow_step_3",
],
threshold: 0.9,
threshold: 0.5,
subtitle: "subtitle-footsteps_snow",
),
Run(Rock): (
@ -242,7 +242,7 @@
"voxygen.audio.sfx.footsteps.stone_step_11",
"voxygen.audio.sfx.footsteps.stone_step_12",
],
threshold: 1.8,
threshold: 1.0,
subtitle: "subtitle-footsteps_rock",
),
QuadRun(Rock): (
@ -260,7 +260,7 @@
"voxygen.audio.sfx.footsteps.stone_step_11",
"voxygen.audio.sfx.footsteps.stone_step_12",
],
threshold: 0.9,
threshold: 0.5,
subtitle: "subtitle-footsteps_rock",
),
Roll: (

View File

@ -275,6 +275,18 @@ impl Body {
)
}
/// The length of the stride of the body, in metres (not accounting for
/// different legs)
pub fn stride_length(&self) -> f32 {
if let Body::Humanoid(body) = self {
body.scaler() * 3.75
} else {
// Rough heuristic
let dims = self.dimensions();
0.65 + (dims.y + dims.z) * 0.6
}
}
pub fn scale(&self) -> Scale {
let s = match self {
Body::BirdMedium(bird_medium) => match bird_medium.species {

View File

@ -58,6 +58,7 @@ impl Body {
quadruped_small::Species::Rabbit => 110.0,
quadruped_small::Species::Cat => 150.0,
quadruped_small::Species::Quokka => 100.0,
quadruped_small::Species::MossySnail => 20.0,
_ => 125.0,
},
Body::QuadrupedMedium(quadruped_medium) => match quadruped_medium.species {

View File

@ -141,27 +141,24 @@ impl Animation for RunAnimation {
* Quaternion::rotation_y(tilt * 0.7 + short * 0.08);
next.hand_l.position = Vec3::new(
-s_a.hand.0
+ foothorir * -1.3 * speednorm
+ (foothoril.abs().powf(2.0) - 0.5) * speednorm * 7.0,
3.0 * speednorm * 0.0 + s_a.hand.1 + foothorir * -7.0 * speednorm,
1.5 * speednorm * 0.0 + s_a.hand.2 - foothorir * 5.5 * speednorm * 0.5
+ foothoril.abs().powf(3.0) * speednorm * 8.0,
-s_a.hand.0 * 1.2 - foothorir * 1.3 * speednorm
+ (foothoril.abs().powf(2.0) - 0.5) * speednorm * 4.0,
s_a.hand.1 * 1.3 + foothorir * -7.0 * speednorm,
s_a.hand.2 - foothorir * 2.75 * speednorm + foothoril.abs().powf(3.0) * speednorm * 8.0,
);
next.hand_l.orientation =
Quaternion::rotation_x(0.6 * speednorm + (footrotr * -1.8) * speednorm)
* Quaternion::rotation_y(footrotr * 0.4 * speednorm + PI * 0.1);
Quaternion::rotation_x(0.6 * speednorm + (footrotr * -1.5 + 0.5) * speednorm)
* Quaternion::rotation_y(footrotr * 0.4 * speednorm + PI * 0.07);
next.hand_r.position = Vec3::new(
s_a.hand.0 + foothoril * 1.3 * speednorm
- (foothorir.abs().powf(2.0) - 0.5) * speednorm * 7.0,
3.0 * speednorm * 0.0 + s_a.hand.1 + foothoril * -7.0 * speednorm,
1.5 * speednorm * 0.0 + s_a.hand.2 - foothoril * 5.5 * speednorm
+ foothorir.abs().powf(3.0) * speednorm * 8.0,
s_a.hand.0 * 1.2 + foothoril * 1.3 * speednorm
- (foothorir.abs().powf(2.0) - 0.5) * speednorm * 4.0,
s_a.hand.1 * 1.3 + foothoril * -7.0 * speednorm,
s_a.hand.2 - foothoril * 2.75 * speednorm + foothorir.abs().powf(3.0) * speednorm * 8.0,
);
next.hand_r.orientation =
Quaternion::rotation_x(0.6 * speednorm + (footrotl * -1.2) * speednorm)
* Quaternion::rotation_y(footrotl * -0.4 * speednorm - PI * 0.1);
Quaternion::rotation_x(0.6 * speednorm + (footrotl * -1.5 + 0.5) * speednorm)
* Quaternion::rotation_y(footrotl * -0.4 * speednorm - PI * 0.07);
//
next.foot_l.position = Vec3::new(

View File

@ -64,7 +64,6 @@ impl Animation for WieldAnimation {
let u_slowalt = (anim_time * 5.0 + PI).cos();
let direction = velocity.y * -0.098 * orientation.y + velocity.x * -0.098 * orientation.x;
let side = velocity.x * -0.098 * orientation.y + velocity.y * 0.098 * orientation.x;
let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori);

View File

@ -9,7 +9,7 @@ use crate::{
};
use client::Client;
use common::{
comp::{Body, CharacterState, PhysicsState, Pos, Vel},
comp::{Body, CharacterState, PhysicsState, Pos, Scale, Vel},
resources::DeltaTime,
terrain::{BlockKind, TerrainChunk},
vol::ReadVol,
@ -26,7 +26,7 @@ struct PreviousEntityState {
time: Instant,
on_ground: bool,
in_water: bool,
distance_travelled: f32,
steps_taken: f32,
}
impl Default for PreviousEntityState {
@ -36,7 +36,7 @@ impl Default for PreviousEntityState {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
}
}
}
@ -61,11 +61,12 @@ impl EventMapper for MovementEventMapper {
let focus_off = camera.get_focus_pos().map(f32::trunc);
let cam_pos = camera.dependents().cam_pos + focus_off;
for (entity, pos, vel, body, physics, character) in (
for (entity, pos, vel, body, scale, physics, character) in (
&ecs.entities(),
&ecs.read_storage::<Pos>(),
&ecs.read_storage::<Vel>(),
&ecs.read_storage::<Body>(),
ecs.read_storage::<Scale>().maybe(),
&ecs.read_storage::<PhysicsState>(),
ecs.read_storage::<CharacterState>().maybe(),
)
@ -115,7 +116,7 @@ impl EventMapper for MovementEventMapper {
underwater,
);
internal_state.time = Instant::now();
internal_state.distance_travelled = 0.0;
internal_state.steps_taken = 0.0;
}
// update state to determine the next event. We only record the time (above) if
@ -124,7 +125,8 @@ impl EventMapper for MovementEventMapper {
internal_state.on_ground = physics.on_ground.is_some();
internal_state.in_water = physics.in_liquid().is_some();
let dt = ecs.fetch::<DeltaTime>().0;
internal_state.distance_travelled += vel.0.magnitude() * dt;
internal_state.steps_taken +=
vel.0.magnitude() * dt / (body.stride_length() * scale.map_or(1.0, |s| s.0));
}
}
@ -167,9 +169,9 @@ impl MovementEventMapper {
if let Some((event, item)) = sfx_trigger_item {
if &previous_state.event == event {
match event {
SfxEvent::Run(_) => previous_state.distance_travelled >= item.threshold,
SfxEvent::Climb => previous_state.distance_travelled >= item.threshold,
SfxEvent::QuadRun(_) => previous_state.distance_travelled >= item.threshold,
SfxEvent::Run(_) => previous_state.steps_taken >= item.threshold,
SfxEvent::Climb => previous_state.steps_taken >= item.threshold,
SfxEvent::QuadRun(_) => previous_state.steps_taken >= item.threshold,
_ => previous_state.time.elapsed().as_secs_f32() >= item.threshold,
}
} else {

View File

@ -32,7 +32,7 @@ fn config_but_played_since_threshold_no_emit() {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
};
let result = MovementEventMapper::should_emit(
@ -56,7 +56,7 @@ fn config_and_not_played_since_threshold_emits() {
time: Instant::now().checked_add(Duration::from_secs(1)).unwrap(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
};
let result = MovementEventMapper::should_emit(
@ -82,7 +82,7 @@ fn same_previous_event_elapsed_emits() {
.unwrap(),
on_ground: true,
in_water: false,
distance_travelled: 2.0,
steps_taken: 2.0,
};
let result = MovementEventMapper::should_emit(
@ -106,7 +106,7 @@ fn maps_idle() {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::zero(),
BlockKind::Grass,
@ -128,7 +128,7 @@ fn maps_run_with_sufficient_velocity() {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::new(0.5, 0.8, 0.0),
BlockKind::Grass,
@ -150,7 +150,7 @@ fn does_not_map_run_with_insufficient_velocity() {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::new(0.02, 0.0001, 0.0),
BlockKind::Grass,
@ -169,7 +169,7 @@ fn does_not_map_run_with_sufficient_velocity_but_not_on_ground() {
time: Instant::now(),
on_ground: false,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::new(0.5, 0.8, 0.0),
BlockKind::Grass,
@ -212,7 +212,7 @@ fn maps_roll() {
time: Instant::now(),
on_ground: true,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::new(0.5, 0.5, 0.0),
BlockKind::Grass,
@ -234,7 +234,7 @@ fn maps_land_on_ground_to_run() {
time: Instant::now(),
on_ground: false,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::zero(),
BlockKind::Grass,
@ -253,7 +253,7 @@ fn maps_glide() {
time: Instant::now(),
on_ground: false,
in_water: false,
distance_travelled: 0.0,
steps_taken: 0.0,
},
Vec3::zero(),
BlockKind::Grass,