- Home /
rotate slowly back to 0, 0, 0
Hi, everyone, I am attempting to make an airplane game that when the player is not pressing the W, S, A and D keys, it slowly rotates back to 0, 0, 0. However, I'm not quite sure how to do this. All help would be appreciated. Here is my code so far:
// move speed var Speed : float; //transform vector private var tv : Vector3 = Vector3.zero; //rotation vector private var rv : Vector3 = Vector3.zero;
function Update () { HandleMovement(); //here is where the rotation part will go } function HandleMovement() { //up & down var ud : float = Input.GetAxis("Vertical") Speed; //left & right var lr : float = Input.GetAxis("Horizontal") Speed;
tv = Vector3(lr, ud, Speed);
rv = Vector3(ud, lr, lr);
transform.Translate(tv * Time.deltaTime);
transform.Rotate(rv * Time.deltaTime);
}
Answer by Extrakun · Apr 10, 2011 at 03:26 PM
You would need a flag to check whether the player has moved; my suggestion is to track the character's old position and compare it with his current one. If the two positions are difference, then the player has moved, and you need not execute the rotate back to default position code.
My suggestion will be to use Quaternion.Lerp to rotate the character back. The sample code down should suits you need.
Your answer
Follow this Question
Related Questions
Need help with rotation script. 1 Answer
Instantiate a rotated object 4 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Rotating towards the mouse. 0 Answers
I am getting a problem with moving and rotating a camera! 1 Answer