- Home /
How do I move this rigidbody?
I have a rigidbody that needs to move with a keypress. I know how to do key input, velocity, forces, and translations, but I don't know which one to use and how to use it. I tried using velocity, but I can't figure out how to make it move diagonally. I tried translations, but that doesn't work well with collisions, and I tried adding a force, but that makes the character keep on accelerating and it slides after the key isn't pressed anymore. I think velocity is probably the answer, but as I said, the diagonal movement isn't working.
Answer by spooneystone · Jun 17, 2015 at 08:35 PM
Try Input.GetAxisRaw to stop the player on the spot and apply it to ("Horizontal") and ("vertical") in the input manager.
like
> float hor = Input.GetAxisRaw ("Horizontal");
>
> float vert = Input.GetAxisRaw ("Vertical");
rb.velocity = new Vector2 (hor * maxSpeed, vert * maxSpeed);
Your answer
Follow this Question
Related Questions
Bug, while checking if rigidbody is moving 0 Answers
Manually Apply Cars Collision Response Force 0 Answers
Collider question 0 Answers