- Home /
How to smooth the movement?
Well, I have an airplane like a f16, however I'd like to rotate it right and left. The problem is that it stops rotating while I don't press any key, so, if my airplane is rotating, i'd like it to continue rotating a little bit also after i have just took up my finger
Hit us with some code so we can see where you are at making this work. Usually people don't just throw code together for others. Post up what you have and more people will try and help you.
Answer by Illogical-Ironic · Aug 31, 2011 at 12:54 AM
You could always set up a variable for the speed at which the plane is turning around.
Lets say you press the right key to turn to the right. As you hold down the key, the variable would gradualy increase, and so would the speed at which the plane turns. And when not pressing any keys to turn, it would gradualy decrease the value of the variable to 0, and the plane would have the desired effect.
Example:
var turnSpeed;
function Update(){
if(rightKey){
turnSpeed ++;
} else {
turnSpeed--;
}
this.transform.rotation.y += turnSpeed;
}
All you would to do is set up a few variables for maximum turning speed, as well as to type some code to make it work with both keys instead of just one. Hope this helps!
Possibly tie that in with $$anonymous$$athf.Clamp to ensure your plane won't rotate too fast if it's held down for a prolonged turn. Possibly do something like turnSpeed -= turnSpeed * 2 in the else to cause a quicker end to the rotation other wise it'll take just as long to slow down as it did to speed up.
Your answer
Follow this Question
Related Questions
2d camera help! 0 Answers
Smooth Rotation Help 1 Answer
How to make an animation finish after looping smoothly? 0 Answers
Move Object Smoothly 1 Answer