Moving a rigidbody-based character controller

Hello,

When checking out tutorials about Rigidbody character controllers (Capsule Collider + RigidBody) on the Internet, I noticed that some people use:

RigidBody.MovePosition() others use rigibody.Addforce() and other use Rigidbody.velocity =

I wonder what are the differences between all the three options?

Even though they all seem to do the same job of moving a character, I think each of them must have other consequences.

Can anybody give us a quick summary of the differences and when should anyone use a precise method?

Kind regards

The best thing to do would be to read the API documentation for each one of these. Also, use them yourself. Experiment with them and see how they work.

The key thing about MovePositionis that it’s only for a kinematic RigidBody. For RigidBodys “kinematic” means “don’t let the physics engine move my RigidBody, I want to move it myself”. Set your RigidBody to kinematic and use MovePosition if you don’t want the physics engine to interfere with the movement of your character.

AddForce and velocity only work with Rigidbodys that are NOT kinematic, (so fully controlled by the physics engine). Use velocity if you want to have full control over object’s velocity. If you know exactly what speed and what direction you want something to move. This could be useful for a player controller because then they will have full control over when the player moves and doesn’t move.

Use AddForce if you want to influence the velocity, but you want the physics to control it ultimately. This is useful for when you want to preserve momentum or if you want a moving object to get knocked around by other objects or forces. This usually the most realistic looking way to move objects, but you sacrifice that precise control. You can use this to make a more “realistic” character controller but it might feel “floaty” since the player would only have indirect control.

4 Likes