Currently I have an object that is built from multiple sculpted prims. When I use llLookAt to make the root object point at a target the object is sometimes rotated on it's LOCAL x axis so that it looks like it has done a partial barrel roll. I would like to correct this roll and any other rotations besides for the z rotation that the object needs to be pointing at the target which will be at the same altitude. In other words, I would like the object to "stand up straight" after the look at before I move it towards the target.
I have tried the following which almost works... I figured all I wanted to do was align the current up axis with the world axis. When I think about it that should solve my problem.
Code:
vector toUp = llRot2Up(llGetRot());
rotation diff = llRotBetween(toUp, <0.0, 0.0, 1.0>
;llSetRot(llGetRot() * diff);
However, depending on the orientation of the subject to the target sometimes to correct the difference in the "up" axis, the object will be rotated on it's local y axis by almost 180 degrees, which does fix the up axis, but causes the object to face the wrong way... I would rather it fix it's roll by using the local x axis instead thus keeping the facing direction the same..
I hope someone can figure out what im talking about. Let me know if you need pictures or anything.
Thank you very much ahead of time.
