c# - Call current speed of an object

Hi everyone,

I’ve been trying to solve this issue for a while now… I’ve tested a lot of things but i never get close to the result i’m looking for.

In my project the player GameObject is always affected by external forces (local gravity or forces added by the player). What i would like to do is to slow down the speed of the object. Is there a way to do that ?

Here is my force code :

players.rigidbody.AddRelativeForce (Vector3.back * thePower * 12);

I’ve tried this :

players.rigidbody.velocity = Vector3.zero;
players.rigidbody.angularVelocity = Vector3.zero;

That does the job, it stops the forces. But i’d like to slow them down. How can i do that ?

Thanks a lot for your help,

If you want to add a little drag to it you could try

Vector3 xDragForce = -players.rigidbody.velocity*fDragFactor;
players.rigidbody.AddForce(xDragForce);

This will add a force against the current velocity.

If you want to directly manipulate the velocity you can try:

players.rigidbody.velocity = players.rigidbody.velocity*fBrakeFactor;