I've been using this tutorial: https://love2d.org/wiki/Tutorial:Physic ... nCallbacks
here is the file where I have the collision code:
Code: Select all
--called in love.load()
function world_load()
--set up world
love.graphics.setMode(1024, 768, false, true, 16)
love.physics.setMeter(100)
world = love.physics.newWorld(0,0,true)
world:setCallbacks(beginContact, endContact, preSolve, postSolve)
player_create()
end
--collisions
function beginContact(a, b, coll)
aBody = a:getBody()
bBody = b:getBody()
debuxText = "collision"
if aBody:getType() == "bullet" and bBody:getType() == "asteroid" then
debuxText = "collisionA"
aBody:setType("bullet_D")
bBody:setType("asteroid_D")
end
if bBody:getType() == "bullet" and aBody:getType() == "asteroid" then
debuxText = "collisionB"
bBody:setType("bullet_D")
aBody:setType("asteroid_D")
end
end
function endContact(a, b, coll)
debuxText = "collision"
end
function preSolve(a, b, coll)
debuxText = "collision"
end
function postSolve(a, b, coll)
debuxText = "collision"
end