1 decade ago by skel1
Here is a condensed version of my code:
This all works fine until the "player" entity dies. If the player entity dies the game locks up and the javascript console says "Can not read property pos of undefined". The weird thing is, if I comment out the x velocity, it works fine. Put x back in and it crashes. I've tried all sorts of combinations of if statements and x vs y, and it is only the x movement that crashes.
What confuses the problem even further, is that this block of code doesn't get called if the player entity isn't active!
Can anyone offer some insight? I've lost three evenings of my very little dev time to this bug and I'm at wits end. Is it something obvious I'm just over looking?
Thanks!
var player = ig.game.getEntitiesByType( EntityPlayer )[0]; // don't move if you're stunned from being hit if(player && (player.pos.x > 0) && !this.beenhit) { var myangle= this.angleTo(player); this.vel.x = (Math.cos(myangle) * this.accel); this.vel.y = (Math.sin(myangle) * this.accel); this.currentAnim.angle= myangle; }
This all works fine until the "player" entity dies. If the player entity dies the game locks up and the javascript console says "Can not read property pos of undefined". The weird thing is, if I comment out the x velocity, it works fine. Put x back in and it crashes. I've tried all sorts of combinations of if statements and x vs y, and it is only the x movement that crashes.
What confuses the problem even further, is that this block of code doesn't get called if the player entity isn't active!
Can anyone offer some insight? I've lost three evenings of my very little dev time to this bug and I'm at wits end. Is it something obvious I'm just over looking?
Thanks!