# Quaternion.LookRotation Issue, need help!

Currently i have a ‘A frame’ which rotates in and out, attached in between this a-frame (parent) is another object (child) which i want to hang freely as i rotate the a-frame back and forth.

To do this I am using the Quaternion.LookRotation function on the ‘hanging object’ to make sure it is always looking down as i rotate the frame, this works perfectly. However when my hanging object gets to a certain Z rotation it then flips the hanging object around 180 degrees! I believe this is because it is trying to find the shortest rotation or something?

Here is the code i currently have attached to my ‘hanging object’:

``````void Update() {

transform.rotation = Quaternion.LookRotation(-Vector3.up, transform.parent.forward);
}
``````

Is there anyway i could stop this from happening? Or even any other method to allow me to do this?

Any help would be HUGELY appreciated, this is very important that this works!

Quaternion.LookRotation
static function LookRotation (forward : Vector3, upwards : Vector3 = Vector3.up) : Quaternion
Description
Creates a rotation that looks along forward with the head upwards along upwards

LookRotation is not what you want here.

Do you want the object to keep the same exact same rotation as its parent rotates? Or do you want it to always look down but have it’s “up” axis in-line with the “forward” axis of its parent?

hey

Yes i basically want to the child object to point down (world space Y axis) no matter what its parents rotation is?

Ive also noticed using the LookAt function on two objects to point at each other they also flip round when there parent gets to a certain rotation!?

Thanks

Well then you can just get your childs rotation Quaternion before the parents starts rotating, and apply this value every frame:

``````private Quaternion initialRotation;

void Start() {
initialRotation = transform.rotation;
}
void Update() {
transform.rotation = initialRotation;
}
``````

of course this will mean that the child will never deviate from its starting orientation… it can still move as usual. If you want you could also do this instead

``````void Update() {
transform.localRotation= transform.parent.localRotation.Inverse;
}
``````

…which is sort of self-explanatory.