Zombie Collision

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
User avatar
tochy97
Prole
Posts: 24
Joined: Sat May 24, 2014 5:06 pm
Location: Dallas, Texas

Zombie Collision

Post 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
Attachments
Platformer.zip
Zip
(36.89 KiB) Downloaded 89 times
Platformer.love
Love
(36.89 KiB) Downloaded 103 times
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Zombie Collision

Post by Ranguna259 »

How are you doing the collision check between the player and the zombies ?
EDIT: The zombies stack on each other
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
tochy97
Prole
Posts: 24
Joined: Sat May 24, 2014 5:06 pm
Location: Dallas, Texas

Re: Zombie Collision

Post 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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Zombie Collision

Post 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
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests