- Home /
Quaternion based slerp to make homing projectile doesn't turn
I have a projectile that I want to home in on a moving target, and I am using Quaternion.Slert to rotate to a calculated rotation from Quaternion.LookRotation, and for some reason, my code doesn't rotate my missile at all.
Here is my code segment:
if(targetTransform != null )
{
Debug.Log("facing target: " + targetTransform.name);
Quaternion wantedRotation = Quaternion.LookRotation(targetTransform.position-projTransform.position);
float timeToRotate = ProjTurnRadiusDegreesPerSec*Time.time;
Quaternion.Slerp(projTransform.rotation,wantedRotation,timeToRotate);
Debug.Log("distanceToTarg: " + (targetTransform.position - projTransform.position).magnitude);
}
When I test my game, the missile just moves forward (I am doing a translate outside of this that moves it forward by its thrust value). The "facing target" code prints out the correct target I am aiming at.
Another oddity, when I output the distance (as shown above), it grows very slowly. Why is this? There is obviously more distance than what is being reported, as I can look at the positions in the inspector, the distance is obviously wrong. What could this mean?
Why doesn't the projectile turn?
Answer by Chronos-L · Mar 17, 2013 at 01:57 AM
projTransform.rotation = Quaternion.Slerp( projTransform.rotation, wantedRotation, timeToRotate);
Yup. I missed that. I wish unity would complain when data is "thrown" away in this manner so it is easier to pick out.
Your answer
Follow this Question
Related Questions
Use Lerp to rotate object 2 Answers
How can you make a nav mesh agent rotate 180 degrees? 1 Answer
How do I rotate on World Axes with Quaternion.Slerp? 2 Answers
Quaternion Slerp is making me mad 2 Answers
Quaternion.slerp rotates instantly. 2 Answers