My goal is to move my object along the x-axis by 1 every time my animate function is called. However, I keep encountering an error that says "cannot read property x of undefined."
To address this issue, I started adding each mesh I create to the sceneObjects array like this:
addToGlScene(mesh, 'player')
By utilizing the addToGlScene function:
function addToGlScene(what, name, glow, storage){
glScene.add(what)
what.name = name
sceneObjects.push(what)
what.userData.glow = {glow: glow}
what.userData.storage = {storage: storage}
sceneObjects[name] = what
}
Despite these efforts, when trying to update the object position in my animate() function using the following method:
sceneObjects['player'].position
I am still getting the same error message.
Even after console logging sceneObjects['player'], it displays a wealth of information:
THREE.MorphAnimMesh {...} // (object details here)
Here is my animate() function:
function animate() {
// Function contents provided below...
}
What could be causing this issue?