mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-09 10:39:46 -10:00
Pin the turtle's walk animation to vanilla's rate
The turtle's flailing feet (#1776) were the walk animation running at its maximum: the generic MoveControl walked the turtle at its full movement speed (0.25), so LivingEntity.updateWalkAnimation's min(distance * 4, 1) saturated at 1.0 and TurtleModel swung the legs at the maximum rate and amplitude. PR #2565 gave the turtle its own pace, but its tests only pin the forward input the control sets, not the rate of the animation the reporter saw. This test pins the symptom: the turtle covers 0.18447 blocks a tick and its walk animation runs at 0.73789, vanilla's min(distance * 4, 1) for that pace. Co-Authored-By: minimax-m3.1-flash (Claude Code) <[email protected]>
This commit is contained in:
1 parent
6817cb4af0
commit
186198afe6
1 file changed
+41
@@ -317,6 +317,47 @@ mod tests {
|
||||
assert_eq!(m.velocity.y, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_leg_animation_runs_at_vanilla_s_rate() {
|
||||
// LivingEntity.updateWalkAnimation turns the distance a tick into
|
||||
// min(distance * 4, 1), and TurtleModel.setupAnim swings the legs
|
||||
// by 8 * that speed, so the rate of the walk animation is the rate
|
||||
// of the walk. The turtle walks at its own pace, so the animation
|
||||
// runs at vanilla's rate instead of at the maximum (#1776).
|
||||
let mut m = strolling_turtle();
|
||||
let mut last = m.position;
|
||||
let mut distance = 0.0_f64;
|
||||
for _ in 0..40 {
|
||||
// Entity.tick keeps the position the tick started at.
|
||||
m.previous = last;
|
||||
// TurtleMoveControl.tick: the forward input.
|
||||
move_control(&mut m);
|
||||
// LivingEntity.travelInAir on grass: the friction influenced
|
||||
// speed is the input speed (grass' friction is 0.6, so it is
|
||||
// not above it), the move uses the motion as it is, and the
|
||||
// motion is then scaled by the friction (0.6) times the air
|
||||
// drag (0.91). The move itself needs a world, so the flat
|
||||
// ground is stepped here.
|
||||
m.move_relative(m.ai.speed, Vec3::new(0.0, 0.0, 1.0));
|
||||
m.position.x += m.velocity.x;
|
||||
m.position.z += m.velocity.z;
|
||||
let drag = f64::from(0.6_f32 * 0.91_f32);
|
||||
m.velocity.x *= drag;
|
||||
m.velocity.z *= drag;
|
||||
// LivingEntity.updateWalkAnimation.
|
||||
m.update_walk_animation();
|
||||
distance = (m.position.x - m.previous.x).hypot(m.position.z - m.previous.z);
|
||||
last = m.position;
|
||||
}
|
||||
// The ground speed: the input (0.06 + 0.125 * (0.25 - 0.06) =
|
||||
// 0.08375) over one minus the drag (0.546) = 0.18447 blocks a tick.
|
||||
assert!((distance - 0.083_75 / (1.0 - 0.546)).abs() < 1.0e-6);
|
||||
// min(distance * 4, 1) for that pace: 0.73789. The generic
|
||||
// MoveControl walked the turtle at the full 0.25, which put it at
|
||||
// 0.55066 blocks a tick and saturated the walk animation at 1.0.
|
||||
assert!((m.limb_speed - 0.737_885_5).abs() < 1.0e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn water_speed_is_cut_away_from_home_and_for_babies() {
|
||||
// updateSpeed in water near home: no cut, the lerp climbs towards
|
||||
|
||||
Reference in new issue
Block a user