Instance rotation crush

hello, i need to assign 2 rotations to an instance. the problem is that i don’t want the first rotation to be overwritten by the second. so i did a resetLocalMatrix(), but my first rotation is still overwritten… do you know how i should proceed to do this?

instance.instance.mesh._rotation._y = BABYLON.Tools.ToRadians(Math.floor(Math.random() * 360));
instance.resetLocalMatrix();

instance.position = this.getPositionInSphere(sphereRadius, pos_centre_sphere);

instance.instance.mesh._rotation = rotation 

thank you in advance for your reply.

Hello :slight_smile:

When you do mesh.rotation = otherRotation it’s an overwrite


If the goal is to rotate two times (for example given some axis), you could use for example :

// Rotate 20° around Y
mesh.rotate(new BABYLON.Vector3(0,1,0), BABYLON.Tools.ToRadians(20.0));
// Rotate again 10° around X
mesh.rotate(new BABYLON.Vector3(1,0,0), BABYLON.Tools.ToRadians(10.0));

hello,
thank you for your reply!

is it possible to start with an absolute rotation for the first rotation and then make a rotation relative to the mesh? or vice versa. because using your method, the mesh doesn’t respect one of my constraints which I need.
here’s a playground which shows what I’m doing. it’s on line 168 where I’d like to add another rotation.

thank

1 Like

Absolutely ! In my previous PG I use mesh.rotate, but the third param is the BABYLON.Space, which is GLOBAL by default, but you can set it to LOCAL.

Example here, setting a random rotatio around Y, after the absolute initial rotation :

this.box.rotate(new BABYLON.Vector3(0,1,0), 2*Math.PI*Math.random(), BABYLON.Space.LOCAL)
2 Likes

hello,
thank you very much for your help

king regard

1 Like