Hello All,
I am new to unity and I am trying to make an object oscillate rotation on the X axis. For Example when it hits a max point rotates the other way till it hit the min amount. I have tried to use the Mathf Ping Pong but it only seems to work with positions. How would I got about getting this Idea done?
Thanks!
kyp
PingPong can be used with any value as it just interpolates a number.
You can create a rotation with ping pong like this. Moves from 0 to 120 degrees around the y axis.
Quaternion.AngleAxis(Mathf.PingPong(Time.time, 120), Vector3.up);
Great! I will try it out thanks!
Mathf.PingPong() doesn’t only work with positions. It just returns a scalar value; it doesn’t know or care about positions or rotations or anything like that.
To oscillate as you describe, one solution would be to create a quaternion for each of the orientations you want to oscillate between, and then use Quaternion.Slerp(), using Mathf.PingPong() to generate the interpolation parameter.
Nice…good to know about Mathf.PingPong. O_o
I actually wrote my own “pingpong” function for jumping…but I think this will work better.
Thanks for the replies, they helped a lot!