Syncing animation rotations and actual object rotation

Hi everyone

I start with a working example: If you want to let your player run around, you probably loop a run animation in-place and update player’s location elsewhere. In Babylon I operate on a parent TransformNode to do transforms like that. Works like a charm.

Now say, in a cinematic, you want to show your player doing a dramatic 180°-turn. Just setting the rotation or animating the rotation vector is not enough. You need fine-grained skeletal movements in order to make it look nice.

However, once you play the animation, the parent TransformNode is unaware of any changes resulting from playing animations. Differently put, the user sees the player character looking in this direction (Model/skeleton) whereas e.g. the VisibilityController shoots its rays in the opposite direction (TransformNode.rotation).

One solution I can imagine would be to update the rotation without actually rotating. I tried “freezeWorldMatrix”. It works initially but catches up after “Unfreeze”. I tried node._rotation but behaves like node.rotaiton. So, is it possible in any way?

Best wishes

Can you share a playground of what you tries as it might help the community having more ideas of what is possible ?

1 Like

Thanks for the reply.

Here is a playground:

Your .gITF-model has rotationQuaternion set, so Babylon will ignore anything you set on rotation property of root-“Mesh”.

A way to get rotation could be like this:


Before you apply this rotation on the root-mesh, you have to apply both, root-mesh and -bone, rotations on Armature/Rig (inbetween root-mesh and root-bone), while bone rotation needs to be inverted. Then i guess it will work to apply rotation on root-mesh.

Example PG:

If rotation is only applied on a known bone it sure is faster to use node or bone directly:

cone.skeleton.bones.find(bone => === "Root").rotationQuaternion

The corresponding Docs:


Thanks @Takemura for the solution. So it is like, let animation play, reverse rotation on skeleton, re-apply on TransformNode. Nice :slight_smile: