- Home /
Object Local Y-Up being forced to be World Y-Up
I currently have a cube translating forward in its local Z while rotating towards another object. Code attached to cube:
public GameObject cubeTarget;
//Movement:
transform.Translate(Vector3.forward* .1f,Space.Self);
//Gives us a simple direction for the Quaternion look method
Vector3 relativePos = cubeTarget.transform.position - transform.position;
//Calc and apply:
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.localRotation = rotation;
This works almost as intended, but I believe the Quaternions are forcing the cube to have it's local Y up be world Y up. I would like the cube to follow the target object and be able to do a loop similar to a plane(which results in its local Y-up actually being World Y-Down) - but when tried in the scene it snaps violently back to Y-up.
I'm sure I'm missing some Euler calculations but I haven't been able to have any success with the functions I found in the docs.
Answer by Waz · Aug 17, 2011 at 08:22 AM
Read the Quaternion.LookRotation documentation, and see the up vector.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers
OnDrawGizmos Debug.DrawLine position is pinching when rotated. 0 Answers
Multiple Cars not working 1 Answer
Player vehicle spins rapidly when facing straight up or straight down 1 Answer