It looks like you're new here. If you want to get involved, click one of these buttons!
function BoxNormalCollision(ObjA,ObjB) local x, y = 0,0 local a = {x= ObjA:getX(), y= ObjA:getY(), w= ObjA:getWidth(), h= ObjA:getHeight()} local b = {x= ObjB:getX(), y= ObjB:getY(), w= ObjB:getWidth(), h= ObjB:getHeight()} if -- first test for any collision ( a.x < b.x+b.w and b.x < a.x+a.w and a.y < b.y+b.h and b.y < a.y+a.h ) then -- test from where does collision come local ax0 = a.x + a.w /2 local ay0 = a.y + a.h /2 local bx0 = b.x + b.w /2 local by0 = b.y + b.h /2 --desno dolje if bx0 > ax0 and by0 > ay0 then if (a.x+a.w) - b.x > (a.y+a.h) - b.y then y = -1 ObjA:setY(b.y-a.h) else x = -1 ObjA:setX(b.x-a.w) end return x,y --desno gore elseif bx0 > ax0 and by0 < ay0 then if (a.x+a.w) - b.x > (b.y+b.h) - a.y then y = 1 ObjA:setY(b.y+b.h) else x = -1 ObjA:setX(b.x-a.w) end return x,y --lijevo dolje elseif bx0 < ax0 and by0 > ay0 then if (b.x+b.w) - a.x > (a.y+a.h) - b.y then y = -1 ObjA:setY(b.y-a.h) else x = 1 ObjA:setX(b.x+b.w) end return x,y --lijevo gore elseif bx0 < ax0 and by0 < ay0 then if (b.x+b.w ) - a.x > (b.y+b.h) - a.y then y = 1 ObjA:setY(b.y+b.h) else x = 1 ObjA:setX(b.x+b.w) end return x,y -- end end return x,y end |
Likes: Apollo14
Comments
http://wiki.giderosmobile.com/index.php/Special:MyLanguage/bump
Here is the official Bump documentation:
https://github.com/kikito/bump.lua
Likes: oleg
https://deluxepixel.com
Likes: MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
https://deluxepixel.com
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
I know this happen cause it tests collision in 1,2,3 .. order from objs table, but for me it was weird enough to have this same issue with box2d
Likes: SinisterSoft, gemboy100