Finding rotation of Child. Why is there no absoluteRotation or locallyRotate methods?

I’m trying to set the position and rotation of an object to be equal to another object that has a parent.

For position I use: object1.locallyTranslate(object2.absolutePosition);

But this isn’t an option for rotation so I have to use the world matrix?

I googled some and tried doing:

var tempWorldMatrix = object2.getWorldMatrix();
object1.rotationQuaternion = tempWorldMatrix .decompose.rotation;

No luck though. Is there a simple standard way people get local rotation in world space? Thanks!

decompose does not work that way it requires parameters for the decomposition to be stored in. See Babylon.js Playground

As usual please supply a simple playground showing your code and what is wrong when asking a question. You will usually get a quicker answer, for one reason it is far easier for a replier to add a correction to a PG than to construct one and so more likely to get a response.


Thank you for the help. I will make a Playground next time.

I turned your solution into the function below and it worked. I originally asked because I was surprised there wasn’t a built in solution like object.absoluteRotation.

let getChildRotation = function(child){ //return the rotation of a child of a parent object by using a temporary World Matrix
    var scale = new BABYLON.Vector3(0, 0, 0);
    var rotation = new BABYLON.Quaternion();
    var translation = new BABYLON.Vector3(0,0,0);

    var tempWorldMatrix = child.getWorldMatrix();
    tempWorldMatrix.decompose(scale, rotation, translation);
    return rotation;