I'm making a game involving asteroids. I have a collision detection function that looks something like this:
function collisions(){
for (j=asteroids.length-1;j>=0;j++){
//do stuff with asteroids[j]
}
}
I tried doing the collision math with the asteroids, but I got this error:
TypeError: Cannot read property 'x' of undefined
My main problem is that when I wrote:
console.log(asteroids[j])
It logged two values, the Asteroid object, and undefined. I thought maybe it was logging undefined from somewhere else, so I wrote:
console.log("1", asteroids[j], "2")
and it returned both the Asteroid object, and undefined, both with a "1" before and a "2" after. Does asteroids[j] have both values? What is happening here? How do I fix this?
Thanks in advance.