- Home /
How to make player rotate using A and D, and then stop rotating?
So I want to make it so instead of the character just moving left and right, I want it to rotate towards that direction then move in that direction, like most games, but I keep finding things that just rotate the player forever like a beyblade :(
if you are using rigidbodies, use rb.angularVelocity, add to rotate one way subtract to rotate the other way.. or set to value you want. You can use GetKeyUp() to set it to 0 and stop the rotation.
Have you got any code demonstrating this?
Answer by Llama_w_2Ls · Apr 03, 2021 at 02:12 PM
So if you press 'D', the player will rotate right then move forward? If so, you can use transform.Rotate()
to do this. Here's some untested code that might do that:
public class PlayerMovement : MonoBehaviour
{
public float RotateSpeed;
void Update()
{
Rotate();
}
void Rotate()
{
// 'A' rotates left
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(new Vector3(0f, -RotateSpeed, 0f));
}
// 'D' rotates right
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(new Vector3(0f, RotateSpeed, 0f));
}
}
}
Your answer

Follow this Question
Related Questions
Player movement restrictions 0 Answers
How do i keep my characters orientation? 0 Answers
Player cannot jump 0 Answers
Movement Position Being Equal to Int 2 Answers
How to dynamically change BGmusic tempo to match player movement speed? 0 Answers