BEST way to get velocity Without rigidbody?

I know you can manually get velocity with Vector3 velocity = (previous - transform.position) but that’s not really smooth. I’ve tried creating an array of the previous 5 transforms over frames and dividing by 5 (subtracting [0] from [4]) but I drop frames and it’s inefficient. What’s the best and most efficient way to get velocity?

Velocity = Displacement / Time

Just like

Speed = Distance / Time

except Velocity is directional so we use displacement instead.

Are you using Time.deltaTime in your math? Or saving Time.time for old frames?

Otherwise different length frames will throw things off. Ex: code moves 10 meters in a 0.1 second update, and correctly moves 12 meters in a 0.12 second update (which is no change in speed.)

Could at least print Time.deltaTime to see if it varies (or do you move in FixedUpdate?)

Using 5 frames back is probably too much. That trick is purposely to make the estimate lag a little behind the real speed. To reduce “jitter,” I think even the previous 2-3 frames should be fine.