how to rotate with arrow keys
i'm brand new to unity and c# so i'm completely in the dark right now
i'm trying to make some limited character movement so you can move forward and back with the up and down arrow keys and rotate side to side with the side arrow keys. i've got the forward and back part but i can't seem to get the rotation to work.
i've tried looking at a bunch of fixes for similar questions on here and youtube but none seem to work, possibly because they're outdated or i'm not putting the code in the right places.
not sure if this would be helpful but here's where i'm at right now
void Start()
{
}
void Update()
{
inputX = Input.GetAxis("Horizontal");
if (inputX != 0)
rotate();
}
void rotate()
{
transform.Rotate(new Vector3(0f, inputX * Time.deltaTime, 0f));
}
You are rotating on Y, but with a very small value. inputX will be -1.0f .. 1.0f. You must decide a speed (degrees per second). Try
float speed = 90.0f;
transform.Rotate(new Vector3(0f, inputX * speed * Time.deltaTime, 0f));
And if you don't see anything, maybe you can try a different axis (Z?).
thank you for your help, i added the change and now i'm getting an error that says "The name inputX does not exist in the current context." do you happen to know what it means?
You do not have inputX declared in rotate() and not in Update() either. Get rid of rotate() and try
public float rotationSpeed = 90.0f;
void Update()
{
float inputX = Input.GetAxis("Horizontal");
transform.Rotate(new Vector3(0f, inputX * rotationSpeed * Time.deltaTime, 0f));
}
Answer by TheIrishKraken · May 15 at 10:31 PM
Do you have a screenshot of your character so I can visually see what your trying to do? So your character moves up and down on the Y axis but you only want him to rotate on the X axis and not move is that correct ?
i'm sorry i can't get a screenshot cause my file got messed up somehow so i'm currently starting over (luckily i didn't get that far lol)
hopefully the drawings explain it instead of making it more confusing. basically the character can only move forwards and backwards and if you want to go a different direction you rotate and then move forward
Your answer
![](https://koobas.hobune.stream/wayback/20220613060606im_/https://answers.unity.com/themes/thub/images/avi.jpg)