I am using the elf example that is a standard example with ThreeJS
Instead of the rotation shown in the example I want to move the object in both the x and y direction. This should be achievable by changing elf.position.x
and elf.position.y
in the init() function.
This issue I am facing it that I created an object(class) of the methods that create an elf so I can create multiple ones. I also have a function that should move the object over time. var e
is not accessible in the move function. When I change it to this.e
and I change this e = collada.scene;
to this.e = collada.scene;
I get the following error: Uncaught TypeError: Cannot set property 'e' of undefined
Code:
class DrawElf {
constructor(scene) {
var e;
this.loadingManager = {};
this.loader = {};
this.scene = scene;
// loading manager
this.loadingManager = new THREE.LoadingManager(function () {
scene.add(e);
});
// collada
this.loader = new THREE.ColladaLoader(this.loadingManager);
this.loader.load('./models/collada/elf/elf.dae', function (collada) {
e = collada.scene;
e.scale.set(30, 30, 30);
e.position.set(100, 10, 100);
e.name = "elf.dae" + 0 + 0;
e.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.name = e.name;
ToIntersect.push(child);
}
});
});
}
move(time) {
// i want to move the object
}
}
Hopefully someone can help out.