Page 1 of 1

Collision problem....(SOLVED)

Posted: Wed Jun 25, 2014 4:48 am
by Biphe
So I have created a simple map, player, and enemy, but i can't seem to do the collisions between the player, enemy and map walls without the player or enemy stopping.
I need a way for the enemy or player to move away from the wall after colliding.

Re: Collision problem....

Posted: Wed Jun 25, 2014 5:20 am
by micha
I cannot do anything in the game, because of these lines:

Code: Select all

if collision(player.x, player.y, player.w, player.h, enemy.x, enemy.y, enemy.w, enemy.h) then
  player:update(dt)
end
This line first checks, if there is a collision between the player and the enemy and only if there is one, the player is updated.

To get started with collision, better start with the player-wall collision. That is a bit easier, because the walls don't move.

The general approach is this: First move the player to the new position (ignoring walls), then check if this movement caused a collision (= collision detection) and if so move the player to the closest position that does not cause a collision.
Additionally, try to separate the movement in x- and y-direction. First move the player in x-direction and resolve the collision if necessary, then do the same for the y-direction.

Re: Collision problem....

Posted: Wed Jun 25, 2014 5:34 am
by Biphe
Thanks.