How do you rigidbody.MovePosition (); in 2 directions at the same time?

Here is what I’ve tried;

    void FixedUpdate () {
        rigidbody.MovePosition (transform.position + transform.forward * Input.GetAxis ("Vertical") *               movementSpeed * Time.deltaTime);
        rigidbody.MovePosition (transform.position + transform.right * Input.GetAxis ("Horizontal") * movementSpeed * Time.deltaTime);
    }
}

Only horizontal movement works.

Could you do “transform.forward + transform.right * Input.ect…”

1 Like

That happens because you are overriding the vertical movement with the horizontal one.
You have to do as RiokuTheSlayer says. First find your movement vector, then apply it to rigidbody.MovePosition.

1 Like

Anyways, what are you using MovePosition for? Is it a character controller or you want to get some kind of custom behaviour?

I believe there are better and easier ways to get character movement, that’s why i’m curious :smile:

Thanks guys :slight_smile:

I’m just trying to keep everything clean, I don’t want all kinds of components and scripts lying around everywhere. I also get some personal satisfaction knowing that I scripted my own movement, simple as it may be.

1 Like