1 decade ago by dlapointeus
We have a simple top down game where an entity moves through maze. The entity's direction is dictated by the position of a touch/mouse, so it follows it around the screen. In addition to the player entity we have a 'position' entity that gets spawned initially, and while the state is being touched, the position entity is updated with the coordinates. The update code for the player looks as follows:
All seems to work fine moving the player around. When we add a collision layer, however, there is some behavior which is giving us a problem/causing some confusion. If the direction of the player is right to left or bottom to top (negative accel), then the entity breaks through the collision map. Changing direction back the other way gives the expected results (as does starting off in the opposite direction). We're sure that we're missing something totally fundamental with how the collision map works. Any insight would be greatly appreciated.
if(ig.game.canvasState == 1){ this.vel.x = this.speed; this.vel.y = this.speed; this.realX = ig.input.mouse.x + ig.game.screen.x; this.realY = ig.input.mouse.y + ig.game.screen.y; // ig.game.position is the position entity ig.game.position.pos.x = this.realX; ig.game.position.pos.y = this.realY; this.pos.x += Math.cos(this.angleTo(ig.game.position)) * this.vel.x; this.pos.y += Math.sin(this.angleTo(ig.game.position)) * this.vel.y;
All seems to work fine moving the player around. When we add a collision layer, however, there is some behavior which is giving us a problem/causing some confusion. If the direction of the player is right to left or bottom to top (negative accel), then the entity breaks through the collision map. Changing direction back the other way gives the expected results (as does starting off in the opposite direction). We're sure that we're missing something totally fundamental with how the collision map works. Any insight would be greatly appreciated.