MoveTowards position isn't effected by rigidbody's velocity. Why?

Well here’s what I noticed. I made an object that move towards another objects position on a certain event.

So I wanted to see how fast it was going so I made a Script statement like this.

moveSpeed = ObjectRB.GetComponent<Rigidbody2D> ().velocity.x;

But when ever my Object would movetowards the designated object on my certain event, I noticed my moveSpeed would remain as 0;


When I push the GameObject with my character. my moveSpeed number begins gaining.

So why is it that the Movetowards function can’t detect my Rigidbody’s velocity?

I’m thinking I get the picture here but I would really love some intel from anyone right now.

Help would be appreciated!

The Rigidbody2D component will change it’s velocity when it interacts with Unity’s Physics system such as collision, forces and direct manipulation of the velocity.

What you are doing is manipulating the position directly, you are not using physics to update the game object hence the velocity will remain unchanged.

When your character is interacting with game object, it is doing so through the physics system, which is why you will see changes in the velocity of the object.

Check out this tutorial for more information about he 2D Physics systems