Why aren't RigidBodies / ChracterController more friendly with setting an absolute position?

Overall rigidBodies and character controllers are very reliable when using the built-in Move(velocity) functions.
However, severe problems always tend to arrive when trying to move a gameobject with an attached rigid body / character controller to a specific location in a scene. It seems to break the character controller.

Consider the following scenario:

  1. You have a character controller moving with
characterController.Move (currentMoveDirection * Time.deltaTime *1.0f);
  1. You execute some instructions to move the character controller manually using:
characterController.transform.position = ...
or
characterController.gameObject.transform.position = ...
  1. Suddenly the character controller pops up and floats above the ground, some distance much greater than that it was before.
  2. The controller continually reports that it is “grounded”, when it is many units above the collider it is on.

These issues do not happen until you start doing step 2 above.
The character controller can settle itself down again once you start bumping into different ground colliders.

Even the API provides no function for moving a character controller to a specific location, which makes me wonder why not.

Even the isGrounded member is a little suspicious: “Was the CharacterController touching the ground during the last move?” (Unity - Scripting API: CharacterController.isGrounded)
Note it doesnt report if it is currently touching the ground, which could be the reason why the above issues are occuring.
So, is there a reliable way to “teleport” a gameObect with a character controller without causing problems to the character controller?

If you set the character’s velocity to the distance between it and the destination divided by Time.deltaTime, it will move there in one frame (watch out for floating point weirdness though, might be better to do this in fixedUpdate, so you can bound how big the numbers you’re dealing with are).

1 Like

That’s an interesting technique, I’ll try that. Thanks.