1 decade ago by robw00t
Hello, I'm working on a top-down game where a fixed entity should prevent a passive entity (the player) from moving through it.
I place the fixed entity in the game world and move the passive entity towards it by updating the passive entity's (player) pos.* values in the update() method:
this.pos.x = this.pos.x + xd; (where xd is x delta)
this.pos.y = this.pos.y + yd;
I know some accel / velocity features exist already but they don't create the movement I want so I'm updating the x and y coordinates manually.
The collision works perfectly when I collide the player with the fixed entity from a vertical approach: the player stops when it hits the entity as expected.
When I approach from a horizontal direction, however, the player 'jumps' to above or below the fixed entity instead of stopping.
If the fixed entity's top most pixel is at y coordinate 10 and the player's bottom most pixel is at y coordinate 15 when the player collides with the fixed entity heading east the player's bottom y coordinate is jumped up to 10 from 15 and the player continues to move east ABOVE the fixed entity instead of stopping.
If I reverse the if statements on lines 288 and 304 of entity.js so the horizontal collision is checked before the vertical one then the problem is reversed; my horizontal collisions work perfectly and the vertical ones cause the player to jump around the fixed entity.
Is this a known bug with the collision engine on top-down games? I'd be happy to provide some source code and/or a video demonstrating the situation.
-Rob
I place the fixed entity in the game world and move the passive entity towards it by updating the passive entity's (player) pos.* values in the update() method:
this.pos.x = this.pos.x + xd; (where xd is x delta)
this.pos.y = this.pos.y + yd;
I know some accel / velocity features exist already but they don't create the movement I want so I'm updating the x and y coordinates manually.
The collision works perfectly when I collide the player with the fixed entity from a vertical approach: the player stops when it hits the entity as expected.
When I approach from a horizontal direction, however, the player 'jumps' to above or below the fixed entity instead of stopping.
If the fixed entity's top most pixel is at y coordinate 10 and the player's bottom most pixel is at y coordinate 15 when the player collides with the fixed entity heading east the player's bottom y coordinate is jumped up to 10 from 15 and the player continues to move east ABOVE the fixed entity instead of stopping.
If I reverse the if statements on lines 288 and 304 of entity.js so the horizontal collision is checked before the vertical one then the problem is reversed; my horizontal collisions work perfectly and the vertical ones cause the player to jump around the fixed entity.
Is this a known bug with the collision engine on top-down games? I'd be happy to provide some source code and/or a video demonstrating the situation.
-Rob