Collision problem....(SOLVED)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Collision problem....(SOLVED)

Post 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.
Attachments
game.love
(2.79 KiB) Downloaded 125 times
Last edited by Biphe on Wed Jun 25, 2014 5:35 am, edited 1 time in total.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Collision problem....

Post 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.
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Re: Collision problem....

Post by Biphe »

Thanks.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest