Alright so I have kind of a weird problem. I need to rotate a parent object in order to orient a child object to a specific direction.
I’m working in VR which means my child object is tracked and I can’t fuck with its rotation in any way, I can only rotate the parent object. Now I need to align this child object to some variable direction at runtime by changing the parent orientation.
This would be pretty easy if I could unparent the child or rotate the child but neither are options. I also have to use a quaternion method of some kind to get a smooth rotation.
So far I’ve had zero luck managing to make this happen though so any help would be appreciated. I imagine this ought to be fairly easy to do with the right knowledge of quaternion math but I haven’t had any luck working it out over the last day.
Ok, I’m pretty sure I’ve solved this for those questing for quaternion rotation solutions in the future.
If you have a look rotation for the direction and alignment you want your child object to have (or any equivalent quaternion) you take the inverse of the child object’s rotation times the look rotation (quaternion subtraction) like so:
Now lookRotationVar will be the rotation you want to rotate your parent object towards in order to correctly orient your child object.
At the very least, this has worked through all my testing so far. In particular though I’ve only tested this working with steamVR and having the camera be the child object.
I had a similar yet different scenario that this helped me with - figured I’d share:
I’m working on an inverse kinematic that allows the arms to be positioned wherever then it sets the joint’s position/rotation to be relative to the arm positions
(the joint is represented as Plane)
The arms are represented by vector1 and vector2 (calculated elsewhere and passed to this code)
Since the arm positions are fuzzy relative to the parent joint, I’m taking the bisecting line and cross product as my two vectors that will control the rotation