How to properly load and move a gltf model


I’m trying to implement a simple game in BabylonJS. I have managed to load a game world which I created in blender, together with obj/mtl model of a player and got the player to move around the world with a collision detection, however now I wanted to swap the simple player model to some animated gltf model, but do not quite understand how to update the loaded gltf model position. The model loads but it ends up under the world.

The way load the gltf model is through this example

BABYLON.SceneLoader.ImportMesh("him", "Scenes/Dude/", "Dude.babylon", scene, function (newMeshes, particleSystems, skeletons) {
    var dude = newMeshes[0];

    dude.rotation.y = Math.PI;
    dude.position = new BABYLON.Vector3(0, 0, -80);

    scene.beginAnimation(skeletons[0], 0, 100, true, 1.0);

However, changing the position/rotation of the object does not change anything. When I have loaded the model into the BabylonJS sandbox, I am able to rotate/translate the model.

Another questions is the model which I’m using has some animations, they are stored inside the animationsGroup property, how could I specify which animation should the object perform, upon loading into the game it plays the first animation from the animationsGroup.

The model which I have used is located here

Thanks for any help

As you can see here:

Your code works and retrieved the parent mesh you can move around.

It also works with gltf/glb files:

Could you share a repro of your issue in the playground ?

About groups, you can retrieve them and play them independently. The group usually wraps a set of anim that needs to be played together.

1 Like

The gltf example is not working. The playground example is not rotating. Im using macbook pro and I cant move or rotate gltf objects. When i console.log rotation i see different values but the model is standing stiff.

This is because by default it uses rotationQuaternion which has precedence over rotation so you could put the quaterion to null and the use the rotation or directly use the rotationQuaternion: