- Home /
Rotate from angle to angle
Currently I am trying to code a 'ping pong' effect. I would like the object to start at angle 0, than rotate to angle 90, than rotate back to 0, etc...
What would be the easiest way to achieve this? Can I use Lerp? Any tips on an optimal setup would be great.
Thanks!
Answer by Eric5h5 · Jul 07, 2011 at 06:49 PM
Strangely enough, Mathf.PingPong is really good for 'ping pong' effects. ;)
var rotateSpeed = 50.0;
function Update () {
transform.rotation = Quaternion.Euler(0.0, Mathf.PingPong(Time.time * rotateSpeed, 90.0), 0.0);
}
Oh my, how did I miss the $$anonymous$$athf.PingPong?
Nice!
I cannot slow down the speed of the rotation, the rotateSpeed variable does not seem to affect the speed at all. Any ideas?
Your answer
![](https://koobas.hobune.stream/wayback/20220612134816im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Transform.Rotate() stuck at 90 and 270 degrees 3 Answers
How can I rotate the transform by a specific angle at a certain speed? 2 Answers
3rd person unit control 0 Answers
Rotate player 360 degrees once 0 Answers
Rotating Joystick on Touch 0 Answers