Page 1 of 1

Zombie Collision

Posted: Sat Jul 19, 2014 6:00 am
by tochy97
Sorry for all the constant post but i tried adding colliosion to the zombies where when its hits another zombie it doesnt just stack on top of each other. and when it hits the player it wouldnt just stack underneath him. noting crashes or anything it just doesnt work. any help would be appreciated. i attached a .zip and .love file of the game

Re: Zombie Collision

Posted: Sat Jul 19, 2014 1:32 pm
by Ranguna259
How are you doing the collision check between the player and the zombies ?
EDIT: The zombies stack on each other

Re: Zombie Collision

Posted: Sun Jul 20, 2014 3:20 am
by tochy97
The left side of the player to the right side of the zombie. pw is playerWidth.

Code: Select all

for i,zz in ipairs(zombie) do
	if zz.x == player.x + pw then
		zz.x = zz.x
	end
end

Re: Zombie Collision

Posted: Sun Jul 20, 2014 3:53 am
by Ranguna259
Your code is wrong if you want to use it for collision detection.
Basic rectangle to rectangle collision detection, zz.h is zombie's height, zz.w is zombie's width, ph is player's height:

Code: Select all

    for i,zz in ipairs(zombie) do
       if zz.x < player.x + pw and player.x < zz.x + zz.w and zz.y < player.y + ph and zz.y+zz.h > player.x then --player and zombie "i" are colliding
          --revert back zombie to the last none safe position
       end
    end