From d73683359a19e0b2b458f09c99dc40287a05d49b Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 22 May 2025 23:17:53 -0400 Subject: [PATCH] Fix apparent jitter in player movement Remember: `time.delta_secs()` needs to be included in ALL movement calculations!!! This one was pretty well hidden because the player movement was properly interpolated and the camera lerped after it, but it was still barely noticeable! --- src/game/runtime.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/game/runtime.rs b/src/game/runtime.rs index 1c2878b..81b1ddf 100644 --- a/src/game/runtime.rs +++ b/src/game/runtime.rs @@ -1,6 +1,7 @@ use avian2d::prelude::*; use bevy::{ input::mouse::{AccumulatedMouseScroll, MouseScrollUnit}, + math::curve::EaseFunction::SmoothStep, prelude::*, }; @@ -14,19 +15,19 @@ pub fn move_player( ) -> Result { let acceleration = 500.0; - let delta_time = time.delta_secs(); + let delta_v = acceleration * time.delta_secs(); if keyboard_input.any_pressed([KeyCode::KeyW, KeyCode::ArrowUp]) { - velocity.y += acceleration * delta_time; + velocity.y += delta_v; } if keyboard_input.any_pressed([KeyCode::KeyS, KeyCode::ArrowDown]) { - velocity.y -= acceleration * delta_time; + velocity.y -= delta_v; } if keyboard_input.any_pressed([KeyCode::KeyA, KeyCode::ArrowLeft]) { - velocity.x -= acceleration * delta_time; + velocity.x -= delta_v; } if keyboard_input.any_pressed([KeyCode::KeyD, KeyCode::ArrowRight]) { - velocity.x += acceleration * delta_time; + velocity.x += delta_v; } Ok(()) @@ -39,10 +40,14 @@ pub fn quit(mut exit: EventWriter) { /// Follow the player character with the camera pub fn move_camera( + time: Res