I am encountering difficulties with updating the positions of my enemies before rendering them.
Instead of creating a separate update() function, I attempted to use an onBeforeRender() function attached to each enemy object.
However, nothing seems to be happening as expected.
Below is the code snippet where the issue might lie:
var i = 0;
for(i = 0; i < num_enemies; i++ ){
//CLONE THE ENEMY FROM THE PROTOTYPE
var enemy = bad.clone(true);
enemy.name = i.toString();
enemy.visible = true;
//SPAWNS ON RENDER POSITION
enemy.position.x = Math.random() * (40) - 20;
enemy.position.y = 0.7;
enemy.position.z = Math.random() * (28) - 14;
self.velocity = new THREE.Vector3(0.1, 0, 0);
//FUNCTION TO BE CALLED BEFORE RENEDER
enemy.onBeforeRender(function(){
self.position.addVectors(self.position, self.velocity);
});
scene.add(enemy);
}