Merge pull request #2748 from levzzz5154/fix/turtle-walk-animation-rate
🤖 Agent: read the diff at 186198afe: test only: the turtle's limb speed follows its walk (`LivingEntity.updateWalkAnimation`, `TurtleMoveControl`). verify green, parity green on this head (merged into main), merges cleanly.
This commit is contained in:
@@ -542,6 +542,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