- Home /
transform.lookat axis switch during rotation
Hello, help please:
Please have a look at this video:
http://www.youtube.com/watch?v=waBAPVVH21k
The blue cubus rotates around the orange one and has a tranform lookat script. As you can see, the axis switches suddenly by 180. How can this be avoided?
Here is the lookatscript:
var myTransform : Transform; //var target : Transform;
function Update () {
transform.LookAt(myTransform); //~ var relativePos = target.position - transform.position; //~ var rotation = Quaternion.LookRotation(relativePos); //~ transform.rotation = rotation;
}
Thanks for helping
Answer by Antony-Blackett · May 14, 2011 at 01:10 AM
try using the objects up vector instead of the default world up vector.
var myTransform : Transform;
function Update () { transform.LookAt(myTransform, transform.up); }
This works like a charm! Thank you for helping everyone out.
This is great, I've been trying to work out how I could fix this for days. Thank you!
Your answer
Follow this Question
Related Questions
Mimic rotation from a joystick 1 Answer
Flip over an object (smooth transition) 3 Answers
How to rotate Character depending on the inclination of the platform or its parts? 1 Answer
player set to 0 on x-axis on play but in editor its set to -90 on x-axis 0 Answers
0-360 Y degree from Vector3.Angle 1 Answer