Tile collision problem

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
stanmarshd
Prole
Posts: 8
Joined: Tue Jul 23, 2013 7:57 am

Tile collision problem

Post by stanmarshd »

I've been making a tile system so that sometimes collision is on, and other times is off.

Code: Select all

function tile:spawn(x, y, coli, img, width, height)
	table.insert(tilem, {x = x--[[int]], y = y--[[int]], coli = coli--[[bool]], img = img--[[string]], width = width--[[int]], height = height--[[int]]})
end
Then I added a if coli is true function.

Code: Select all

function tilep:coli()
for i,v in ipairs(tilep) do
if v.coli == true then
if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y >= v.y - 21 and char.y <= v.y + v.height - 21 then
					char.y = v.y - 21
				end
				if char.x >= v.x and char.x <= v.x + v.width and char.y >= v.y - 21 and char.y <= v.y + v.height - 21 then
					char.y = v.y - 21
				end
				if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y <= v.y + 21 and char.y >= v.y - v.height + 21 then
					char.x = v.x - 14
				end
				if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y <= v.y and char.y >= v.y - v.height then
					char.x = v.x - 14
				end
			end
end
end
end
I don't get any errors, but collision isn't how I'd like it to be. At some point, when hitting the tile to the left, it works. At others, it moves the player up. Please help me.
All you need is LÖVE
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Tile collision problem

Post by CaptainMaelstrom »

From just glancing, maybe line 7 needs to be:

Code: Select all

if char.x >= v.x -14 and char.x ... 
instead of

Code: Select all

if char.x >= v.x and char.x ...
Hard to say without you uploading a .love for us to look at.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests