# How to rotate a node relative to another node which is not the parent

**URL:** <https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185>\
**Category:** Questions\
**Created:** [March 27, 2019, 7:33pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185 "2019-03-27T19:33:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauricedoepke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mauricedoepke/32/1360_2.png) [@mauricedoepke](https://forum.babylonjs.com/u/mauricedoepke)\
**Post date:** [March 27, 2019, 7:33pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/1 "2019-03-27T19:33:12Z")

</div>

I have a bone in a skeleton, which I want to rotate relative to a mesh’s Space. World or Local Space don’t work in my situation.  
I there an easy way to do that?

I have some constraints that make this task easier:  
The rotation Axis I want to achieve for the bone is perpendicular to the character it belongs to.  
The character only turns around the Y Axis in world space.

I already did some research on the world matrices, but they only support converting locations.  
I too tried to create my own quaternion with the above mentioned axis, but that only resulted in weird distortions. Though I think this is the way to go, I just can’t figure out the math + the right api functions to use.

---

<div class="post-metadata">

**Author:** ![mauricedoepke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mauricedoepke/32/1360_2.png) [@mauricedoepke](https://forum.babylonjs.com/u/mauricedoepke)\
**Post date:** [March 27, 2019, 8:50pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/2 "2019-03-27T20:50:20Z")

</div>

I got a roughly working version, but it only works shortly. After a while, the floating point errors add up as I am only setting the delta rotation.

Is there a way to set an absolute position with the world axis as the reference? That would solve my problem.

```
const axisMeshRotation = axisMesh.rotationQuaternion.toEulerAngles();
boneToRotate.rotate(BABYLON.Axis.X, Math.cos(axisMeshRotation.y) * .3, BABYLON.Space.WORLD);
boneToRotate.rotate(BABYLON.Axis.Z, -Math.sin(axisMeshRotation.y) * .3, BABYLON.Space.WORLD);
```

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [March 28, 2019, 4:05pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/3 "2019-03-28T16:05:58Z")

</div>

Can you create a playground of what you have so far? That will help a lot.

---

<div class="post-metadata">

**Author:** ![mauricedoepke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mauricedoepke/32/1360_2.png) [@mauricedoepke](https://forum.babylonjs.com/u/mauricedoepke)\
**Post date:** [March 29, 2019, 1:47pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/4 "2019-03-29T13:47:53Z")

</div>

Here is the playground:

[https://www.babylonjs-playground.com/#JUKXQD#127](https://www.babylonjs-playground.com/#JUKXQD#127)  
Just press any key to pause he rotations, there is a high chance, that the arm will stuck in the body.

Note: I rotate the arm by rotating the node associated with the bone.  
Bones itself have methods to do absolute rotation, but if i change the arm rotation directly through the bone (no matter if by code, or in the inspector) it is ignored by babylon.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [March 29, 2019, 4:30pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/5 "2019-03-29T16:30:45Z")

</div>

Probably something like this is what you want:  
[https://www.babylonjs-playground.com/#JUKXQD#128](https://www.babylonjs-playground.com/#JUKXQD#128)

For glTF, bone transforms are being linked to nodes which is why changing the bone transforms have no effect.

---

<div class="post-metadata">

**Author:** ![mauricedoepke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mauricedoepke/32/1360_2.png) [@mauricedoepke](https://forum.babylonjs.com/u/mauricedoepke)\
**Post date:** [March 29, 2019, 6:45pm UTC](https://forum.babylonjs.com/t/how-to-rotate-a-node-relative-to-another-node-which-is-not-the-parent/2185/6 "2019-03-29T18:45:42Z")

</div>

Thank you very much, this is exactly what I was looking for.
