Parent loaded character to Babylon box

I’m trying to parent a character mesh loaded with the asset manger to a box created with Babylon.
I want to use the box for collisions or is there a better way to do this?

class Player {
	constructor(game) {
        this.game = game;
    }
    load() {
        this.box = BABYLON.MeshBuilder.CreateBox("parent", {height: 0.5, width: 0.5, depth: 0.5}, this.game.scene);

        var meshTask = this.game.assetsManager.addMeshTask("character", "", "./assets/character/", "Walk.glb");
        meshTask.onSuccess = function (task) {
            task.loadedMeshes[0].position = BABYLON.Vector3.Zero();
            this.character = task.loadedMeshes[0];
            
            this.character.setParent(this.box);
            
        }
        this.game.assetsManager.load();
         
    }
}

Got it to work with physics.

1 Like