- Home /
Rotating on key press and strafing for the fps camera
I'm using a grid movement system and I'm trying to figure out how to rotate my first person character with a key press and have him strafe or sidestep left and right. The character moves and rotates, but that's together. I want the character to rotate separately. I should probably say that I'm using the js version of the GridMove script Eric5h5 created. I could probably use the C# version considering the character doesn't rotate in that script. Which ever one is easier for you to help me on.
Edit: I got it with the following code but it turns way to fast. How do I slow it down. Also I forgot to say that I need it to rotate in 90 degree angles.
if (Input.GetKey(KeyCode.E)) transform.Rotate(0, 90, 0);
if (Input.GetKey(KeyCode.Q)) transform.Rotate(0, -90, 0);
Answer by AchillesWF · Apr 22, 2012 at 03:36 AM
If you want to slow it down you'll need to do the rotation in more than just a single frame as you are currently doing. Rotate in the direction you want, using a function like Slerp() to control how much of the rotation is actually performed during a single frame. You can set a target rotation, then in each update call if you are not at your target rotation, rotate a little bit more towards the target, clamping your rotation when you get there.
I completely looked past that. Thank you. It works perfectly.