Preventing Movement - Character Controller - 2D

Hello everybody,

So I want my character to NOT move when stumbling upon rigidObjects, I’ve attached character controller to my player and added a boulder Object.

I had my character have rigid body && box collider but I was told character controller might be more suitable when using the player.

But when I “collide” with objects it keeps moving, what am I missing?

The setup is as follows:

Player: has character controller attached and when it moves it moves as follows":

When up button is pressed:

transform.Translate (Vector3.up * speed * Time.deltaTime);

Boulder Object is as follows"

Rigidbody2D && box Collider2d attached…

Thanks for your time and help!

You shouldn’t move gameobject that have a rigidbody or a character controller with translate. Translate will “teleport” your gameobject right to the position, and thus not detecting collision. Use rigidbody.MovePosition for gameobject with rigidbody or SimpleMove or Move with character controller.

public float speed = 3.0F;
public float rotateSpeed = 3.0F;

    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        float curSpeed = speed * Input.GetAxis("Vertical");
        controller.SimpleMove(forward * curSpeed);

Take a look at Character Controller Unity API