- Home /
Rotate slowly to face target.
This is probably an easy one, but I'm stumped. I have a missile using this code to seek:
Vector3 lookDirection = target.position - transform.position;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookDirection.normalized), Time.time * turnSpeed);
transform.Translate(Vector3.up * velocity, Space.Self);
My problem is it arcs slowly to a spot 80 or so units above the target, then flies in tight little circles. What am I doing wrong?
Answer by Statement · Mar 10, 2011 at 01:45 AM
You're moving up, not forward. Try translating forward instead.
transform.Translate(Vector3.forward * velocity, Space.Self);
Except it's a missle so my goal is to have its "up" be facing my target. I see my problem now, but I'm not sure how to get the LookRotation to spit out what I need.
Fuckit I just put my script in a wrapper and rotated the child cylinder so the missile's "forward" is the cylinders "up". If you know how I could do it the other way I'd still like to know for future reference working with these types of problems.
If you were to use the up vector being forward vector, you'd have to rotate the quaternions equally. I am not in a state of $$anonymous$$d of going in depth of it. To be honest, I think your approach of having the forward vector being forward is most reasonable and will probably save you a lot of head ache in the future.
I hate headaches, so I will simply use forward as my direction of motion from now on. :)
Your answer
Follow this Question
Related Questions
Turret script. Making it aim in heigth only. 1 Answer
Constraint not totally working after manually overriding a joint rotation 0 Answers
Axis-clamping a transform rotated with a Quaternion 1 Answer
How to do 2D aiming 2 Answers
Aiming to gameobject 2 Answers