Why Rigidbody2D.velocity returns 0 even though the object is actually moving ?

I have a gameobject following another gameobject by using this in update:

transform.position = Vector2.MoveTowards(transform.position , target.position , speed * Time.deltaTime);
Debug.Log(rb.velocity.magnitude);
*

I always take (0.0 , 0.0) by the console even though my object does moves. Does anyone know what causes to this behaviour ?

You’re just changing it’s position, but the rigidbody’s velocity it’s not calculated like

(s1 - s0 ) / (t1 - t0)

From th e documentation :

The value is not usually set directly but rather by using forces.

It means the velocity is calculated with forces. Also, you can change it manually. But it has nothing to do with previous position and current position in a certain time.

You need to get the rigidbody in motion, not just the transform. Use Rigidbody2D.MovePosition instead of Vector2.MoveTowards. Of course, setting MovePosition isn’t the same as the MoveTowards function, so you’ll need to do a lerp yourself. Something like myRigidbody.MovePosition(Vector3.Lerp(myRigidbody.position, targetPosition, Time.deltaTime * speed)); Since this is physics movement code, make sure it runs in FixedUpdate as well!

Thank you for both answers ! @ryanreptoid @ConcanoPayno. These definetly solves my problem.