Wednesday, March 14, 2018

Unity: How to move a player using Character controller in step?

Leave a Comment

I would like to move my Player in "block" of 0.1 unity unit (or 1).

How to modify / configure Character controller to move with "fixed" step?

2 Answers

Answers 1

You can use transform.Translate to move the character

    //moves the character 1 unit in x direction     transform.Translate(1.0f, 0.0f, 0.0f); 

Answers 2

If you want to use the Character Controller component to move your object, you would want to use its dedicated methods:

  1. Move
  2. SimpleMove

Also, there's some difference between the 2 methods stated above.
The Move method is more complex and performance wise. As it takes care of complex physics such as gravity, collisions and will move the object by motion.
The SimpleMove method, instead, is more lightweight because it will only move the object without taking care of environmental physics.

If you want to move by a single unit, probably the code should look something like this:

//Controller being your character controller component Controller.SimpleMove(Vector3.forward); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment