Objects still moving with 0 Velocity

Hi,
I’m new to unity but have has some experience with game programming before.
Today i noticed Unity’s physics engine won’t allow interception from script. What i mean is that
when i set a rigidbody’s velocity to zero, i can still see the objects moving slowly.

I suspect this is due to the physics engine will integrate gravity and add this to velocity of the rigidbody.
But weird thing is when I set velocity in all the update functions, it still move.

And this contradicts the documentation about the execution order of unity. Unless the physics simulation actually translates the objects too.

Anyway so my issue is basically not sure how to aquire total control of object motion, so if i want to implement my custom friction model to my objects, i can be sure no other hidden forces will move my objects

Code i used for test:

public class UpdateTest : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		rigidbody2D.velocity = Vector2.zero;
	
	}

	void FixedUpdate() {
		rigidbody2D.velocity = Vector2.zero;
	}

	void LateUpdate()
	{
		rigidbody2D.velocity = Vector2.zero;
	}
}

If you want to stop a rigidbody, you want to freeze its transformation. Setting the Velocity to 0 does not remove the forces that operate on it (such as gravity, or residue force from a bullet impact).

Hi thank you for your reply. I don’t want to freeze it, I want to nullify all previous forces/velocities/motions before i apply my custom ones.

Heya… In that case, setting the velocity to 0 should work. But note that again, this won’t remove all the force that is operating on the object (such as gravity), it’ll just nullify it during that frame. So any other forces you want to apply you ought to do in that single frame. Note that you should also set angularVelocity to 0 as well.

1 Like

Hm, thank you, i found a solution, it was to apply the opposite force of gravity to cancel gravity since this was the most troublesome force (such as making things slowly slide down slopes).

What’s wrong with setting the rigidbody’s useGravity to false?