How to move glb model


I am trying to move(animate) the glb model when click, how do you change the position of the imported model? when I try to model.position.x, it says model is undefined.

let model;
const makeModel= function(modelPath, px, py, pz){
loader.load(modelPath, (gltf) => {
  model = gltf.scene;
  model.position.x = px;
  model.position.y = py;
  model.position.z= pz;

makeModel('/models/model.glb', -1, -0.4, 0);


Hey, its happen because you assign the model inside function… change the function into a class it will be easier and you will be able to move the model

1 Like

This code is executed before the model is loaded. You can only use model after the onLoad() callback has been executed.