- Home /
2D Car rotation to forward and backward
Hi guys, I'm working on a 2d car game which moves, but I wanted to add Car rotation to it when you press "A" or "D", so I did this:
if (Input.GetAxisRaw("Horizontal") > 0) //d { transform.Rotate(0, 0, -1 rotateSpeed); } if (Input.GetAxisRaw("Horizontal") < 0) //a { transform.Rotate(0, 0, 1 rotateSpeed); } else {
}
This works well but it rotates weird and the car does not keep rotating smoothly when I release the button
One problem at a time.
What do you mean by "it rotates weird"? (Does it jitter? Is the rotation speed inconsistent? etc)
In which Unity function did you place the code?
Have you considered multiplying rotateSpeed by Time.deltaTime to ensure that the rotation does not depend on the framerate?
Are you intentionally using GetAxisRaw ins$$anonymous$$d of GetAxis? Because GetAxis could help you simulate simple acceleration/deceleration, but I wouldn't use it to add inertia to your object's rotation because inertia should not be directly dependent on input in my opinion. But, like I said, one problem at a time. Fix the "weird rotation" first.
Your answer
Follow this Question
Related Questions
Object leaning with 2D movement 2 Answers
How do I stop unwanted rotations? 4 Answers
How to make an object move in one direction and make it change direction by touching it 1 Answer
Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers
Rotation relativ animation paramter 0 Answers