In my ThreeJS project, I am working with the elf example from ThreeJS
Instead of simply rotating the object as shown in the example, I want to move it in both the x and y directions. To achieve this, I plan on updating the elf.position.x
and elf.position.y
values within the init() function.
The issue I am currently encountering is related to creating multiple instances of the elf object using a method within a class. Additionally, I have a function intended to move the object over time. However, I am unable to access the e
variable within the move function. When attempting to change it to this.e
and updating e = collada.scene;
to this.e = collada.scene;
, I receive an error stating:
Uncaught TypeError: Cannot set property 'e' of undefined
Here is the code snippet:
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) {
// logic for moving the object goes here
}
}
I would appreciate any assistance with this problem.