The effect I want is when I press the left and right arrow keys, the player character rotates by 90 degrees over a short time, so it isn't so snappy. How do I script the actual rotation code when the rotation values are switching between 180 and -180 so often?
Other version of Murcho's example is:
// This should be set to degrees per second
float rotationAmount = 90.0f;
void Update()
{
// Clamps automatically angles between 0 and 360 degrees.
transform.Rotate (0, rotationAmount * Time.deltaTime, 0);
}
Define a rotation speed, and then multiply that by Time.deltaTime in you update loop. If using Euler angles to perform the rotation, you can clamp between 0 and 360 very easily.
// This should be set to degrees per second
float rotationAmount = 90.0f;
void Update()
{
Vector3 rot = transform.rotation.eulerAngles;
rot.y = rot.y + rotationAmount * Time.deltaTime;
if(rot.y > 360)
rot.y -= 360;
else if(rot.y < 360)
rot.y += 360;
transform.eulerAngles = rot;
}
Instead of thinking in terms of absolute rotation, which indeed will switch signs on you, all you really need to do is add or subtract 90 degrees from whatever the current rotation is. Don't worry if you go past 180 or 360; the math should handle that case.
You also seem to be asking how to rotate it smoothly over time. You can do this by interpolating between the starting angle, whatever it is, and the final angle, which is 90 degrees more or less. See Mathf.Lerp for a function that will help you calculate what the angle is after a certain amount of time. (Also see the answer to this question, which is solving a problem of smooth movement rather than smooth rotation, but the idea is similar.)