Move 3D imported model

Hello guys, I’m having some trouble in my initial project with Babylon.js.
I have imported my model 3D at the project, as I show bellow:

tank = BABYLON.SceneLoader.ImportMesh("","",“Models/model003.babylon”,
scene,function(newMeshes) {
mesh.rotation = new BABYLON.Vector3(BABYLON.Tools.ToRadians(
} );

So far so good but now I want to add buttons in order to translate the object.
I’ve tried this:

if (bla==1){
var posX = Math.sin(tank.rotation.y);
var posZ = Math.cos(tank.rotation.y);
tank.position.x += posX;
tank.position.z += posZ;
if(bla == 2){
tank.rotation.y = tank.rotation.y + 0.1;
if(bla == 3){
tank.rotation.y = tank.rotation.y - 0.1;

But the console shows the error “0: Unable to get property ‘y’ of undefined or null reference” so… what should I do ?

Hello and welcome to the forum !!!

ImportMesh does return the mesh but pass it through the callback so

tank = BABYLON.SceneLoader.ImportMesh...

will set tank to undefined.

You could either run this:


as part of the callback or rely on the async version to use promises.

Hope that helps.

I really appreciate your answer, thank you.

Could you give me some exemple ?

should do.

1 Like

It was very helpful, thank you sir :+1:

1 Like