help with collisions
Posted: Sun Oct 14, 2012 3:04 am
I'm trying to make an asteroids clone and I cant seem to make the collisions between my bullets and the asteroids do anything. For the moment, im only trying to make the bullet disappear when it hits an asteroid. I don't have the asteroids set as dynamic bodies to make it easier to hit them for testing.
I've been using this tutorial: https://love2d.org/wiki/Tutorial:Physic ... nCallbacks
here is the file where I have the collision code:
also, Im having trouble with the objects looping around the screen. Sometimes it works fine, and other times they just pop up in weird places. So any help with that would also be appreciated
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