Collision Explanation
Posted: Mon Jan 07, 2013 8:36 pm
This is my collision function
I dont really understand whats going on in this CheckCollision function but my enemies seem to collide at the wrong points and a bit randomly.
As a extension if i want my enemies to face me at all time how would i change this function to fit the way there facing
Checkcollision
Code: Select all
for ii,vv in ipairs(enemies) do -- shot:enemy collision for zombies
if CheckCollision(v.x,v.y,16,16,vv.x,vv.y,vv.width,vv.height) then
table.insert(remEnemy, ii)
table.insert(remShot, i)
As a extension if i want my enemies to face me at all time how would i change this function to fit the way there facing
Checkcollision
Code: Select all
function CheckCollision(ax1,ay1,aw,ah, bx1,by1,bw,bh)
local ax2,ay2,bx2,by2 = ax1 + aw, ay1 + ah, bx1 + bw, by1 + bh
return ax1 < bx2 and ax2 > bx1 and ay1 < by2 and ay2 > by1
end