And what I want to achieve is that 1 also becomes true. And 2 actually should never happen, since you hit the wall.
So I'm trying to figure out how to do this. I thought of adding the movement speed to the function, but that didn't really work.
My checkCollision function
Code: Select all
function checkCollision(x1,y1,w1,h1,hspd,x2,y2,w2,h2,c)
local bbleft1, bbright1, bbup1, bbdown1, bbleft2, bbright2, bbup2, bbdown2, check = x1 - w1-hspd, x1 + w1+hspd, y1 - h1, y1 + h1, x2 - w2, x2 + w2, y2 - h2, y2 + h2, c
if (bbright1 >= bbleft2 and bbleft1 <= bbright2) and (bbup1 <= bbdown2 and bbdown1 >= bbup2) then
if check == "bot" then
if bbdown1 >= bbup2 and bbup1 <= bbup2 then
return true
else
return false
end
end
-----------
if check == "top" then
if bbup1 <= bbdown2 and bbdown1 >= bbdown2 then
return true
else
return false
end
end
-----------
if check== "right" then
if bbright1 >= bbleft2 and bbleft1 <= bbleft2 then
return true
else
return false
end
end
-----------
if check== "left" then
if bbleft1 <= bbright2 and bbright1 >= bbright2 then
return true
else
return false
end
end
-----------
else
return false
end
end
How can I do this?
Thank you in advance.