Ok, I already have a headache trying to do this, i kind of managed to make it work but i need some serious math class about rotations. What i need is the following.. Facts: 1. I have two gameObjects 2. Both move 3. Both can be facing anywhere Problem: I need a script that rotate one gameObject until it faces the other, Quaternion.Slerp seems to solve the problem except for the fact that i need a constant rotation (i.e. 5 degrees per second). With Quaternion.Slerp I'm getting a fraction between the two given rotations that decreases as they came closer. So, i need another function or algorithm to do this, or keep using Quaternion.Slerp but have a dynamic factor for this function ? Any ideas ? Couldn't find anything in the forum. .org
Omar, I am not 100% sure if this is what you are asking for but in calling Quaternion.Slerp, there is a 3rd property that deals with the advancing of the rotation over time. Code (csharp): Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed); Also, in the Mathf class there is LerpAngle that could prove useful. HTH.
littlelingo, Yeah, that would work if from.rotation and to.rotation were fixed, but in my problem, those values varies each frame. If your variable speed is the same always, then the object will rotate at different speeds when rotating from 0 to 45 and rotating from 0 to 180. Am I wrong ? .org
If you have the starting and ending rotations, you can find the angle between them using Quaternion.Angle. If you want a particular rate of rotation (5º per second, say) then divide the angle by this rate to get the number of seconds the rotation should take. Then, use Quaternion.Slerp and vary the interpolation value from zero to one over that time period.