- Home /
How can my character move horizontally with Rigidbody.MovePosition?
How can i make my character go right and left? It only moves up and down. The Rigidbody is kinematic and I want to move him in a plane. Thanks!
P.S. I'm very new to this.
void FixedUpdate() { float h = Input.GetAxis("Horizontal");
rb.MovePosition(transform.position + transform.right * h * speed);
float v = Input.GetAxis("Vertical");
rb.MovePosition(transform.position + transform.up * v * speed);
}
}
Answer by TreyH · Feb 21, 2018 at 08:12 PM
I think you might be overwriting the first call. :-)
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
rb.MovePosition(transform.position + (transform.right * h + transform.up * v) * speed);
Answer by Bomberking · Feb 22, 2018 at 07:00 PM
Thank you so much @TreyH!!! :)
np! In the future, if an answer solves your problem, then be sure to mark it as the answer so that this thread will not come up as an "Unanswered Question" for others. :-)
Answer by SamlicsX · Oct 06, 2020 at 06:54 AM
My object started going up so keep the speed 0 and your object will only move horizontally.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Sprite Sheet animation without fancy add-ons 1 Answer
Changing multiple toggle states. 0 Answers
if it's you, how will you solve it ? 1 Answer