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.
Collision problem....(SOLVED)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Collision problem....
I cannot do anything in the game, because of these lines:
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.
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
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.
Check out my blog on gamedev
Who is online
Users browsing this forum: No registered users and 0 guests