From a94b42ae36fe007c0bf584d876ab17224c03d121 Mon Sep 17 00:00:00 2001 From: megaproxy Date: Sun, 12 Jul 2026 18:52:44 +0100 Subject: [PATCH] =?UTF-8?q?M1:=20smooth=20player=20movement=20=E2=80=94=20?= =?UTF-8?q?ramp=20velocity=20(accel/decel)=20not=20instant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instant full-speed-on-press / dead-stop-on-release was the jerky/jarring feel and made the anim pop Idle->Run. Now MoveTowards-ramps horizontal velocity (accel 45, decel 60 m/s^2), so starts/stops ease and Idle->Walk->Run blends. Co-Authored-By: Claude Opus 4.8 (1M context) --- Assets/Scripts/Player/PlayerAvatar.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Player/PlayerAvatar.cs b/Assets/Scripts/Player/PlayerAvatar.cs index d8cf657..6c9eaaf 100644 --- a/Assets/Scripts/Player/PlayerAvatar.cs +++ b/Assets/Scripts/Player/PlayerAvatar.cs @@ -33,6 +33,12 @@ namespace Jankenbots.Prototype [Tooltip("Run speed in m/s.")] public float moveSpeed = 5f; + [Tooltip("How fast the avatar ramps UP to full speed (m/s^2). Lower = floatier start.")] + public float acceleration = 45f; + + [Tooltip("How fast the avatar ramps DOWN to a stop (m/s^2). Higher = snappier stop.")] + public float deceleration = 60f; + [Tooltip("How fast the avatar turns to face its movement direction (deg/s).")] public float turnSpeed = 720f; @@ -46,6 +52,7 @@ namespace Jankenbots.Prototype CharacterController _cc; Animator _anim; float _vy; // vertical velocity (gravity) + Vector3 _horizVel; // smoothed horizontal velocity (ramped, not instant) Vector3 _lastPos; float _animSpeed; static readonly int SpeedHash = Animator.StringToHash("Speed"); @@ -98,16 +105,23 @@ namespace Jankenbots.Prototype Vector3 input = new Vector3(h, 0f, v); if (input.sqrMagnitude > 1f) input.Normalize(); - Vector3 move = input * moveSpeed; + Vector3 desired = input * moveSpeed; + + // Ramp velocity toward the target instead of snapping — this is what kills + // the "jerky/jarring" feel and lets the anim blend Idle→Walk→Run smoothly. + float rate = input.sqrMagnitude > 0.001f ? acceleration : deceleration; + _horizVel = Vector3.MoveTowards(_horizVel, desired, rate * Time.deltaTime); if (_cc.isGrounded && _vy < 0f) _vy = -2f; _vy += gravity * Time.deltaTime; - _cc.Move((move + new Vector3(0f, _vy, 0f)) * Time.deltaTime); + _cc.Move((_horizVel + new Vector3(0f, _vy, 0f)) * Time.deltaTime); - if (move.sqrMagnitude > 0.01f) + // Face the way we're actually moving (uses the smoothed velocity, so turns + // ease too rather than snapping on a key change). + if (_horizVel.sqrMagnitude > 0.05f) { - Quaternion target = Quaternion.LookRotation(new Vector3(move.x, 0f, move.z)); + Quaternion target = Quaternion.LookRotation(new Vector3(_horizVel.x, 0f, _horizVel.z)); transform.rotation = Quaternion.RotateTowards(transform.rotation, target, turnSpeed * Time.deltaTime); } }