1 decade ago by Elsombrero
Hi, I'm trying to understand the mechanics of why and how this code works. It's to detect if the AI is near an edge or not and to turn in the opposite direction if there's no collision tile. Thanks in advance.
update: function(){ //near edge detection if(!ig.game.collisionMap.getTile( this.pos.x + (this.flip ? +4 : this.size.x -4), this.pos.y + this.size.y+1 ) ){ this.flip = !this.flip; } var xdir = this.flip ? -1 : 1; this.vel.x = this.speed * xdir; this.currentAnim.flip.x = this.flip; this.parent(); },