Collision and destroy problems
Posted: Thu Nov 06, 2008 3:04 pm
For whatever reason, my collision function will not detect ANY collisions.
I'm just trying to detect if any of the bullets fired (all the bodies are stored in the "bullets" table, and the shapes are also stored exclusively in the "bulletShapes" table) so I can add some damage to the mob.
The weird thing is, I can't even get any callbacks from collision, even with just a simple text display; so it's probably not my code that's wrong.
Did the callback change in 0.5.0?
Also - whenever I CAN get to a point to use :destroy() to get rid of the bullets (I cheated and tried doing it in the update function checking distance, but that's hacky and I want the actual collision function to do it because my mob is a diamond, so the collisions wouldn't be right) LOVE errors and says "attempt to call method 'destroy' (a nil value)". I know you have to delete the shapes first, but it's just erroring.
Code: Select all
function collision(a,b,c)
local f, r = c:getFriction(), c:getRestitution()
local s = c:getSeparation()
local px, py = c:getPosition()
local vx, vy = c:getVelocity()
local nx, ny = c:getNormal()
for k, v in pairs(bulletShapes) do
if a == v or b == v then
if b == mobShape or a == mobShape then
mobDamage = mobDamage + 2
end
bulletIndex = k
a:destroy()
b:destroy()
bullets[k]:destroy()
end
end
end
The weird thing is, I can't even get any callbacks from collision, even with just a simple text display; so it's probably not my code that's wrong.
Did the callback change in 0.5.0?
Also - whenever I CAN get to a point to use :destroy() to get rid of the bullets (I cheated and tried doing it in the update function checking distance, but that's hacky and I want the actual collision function to do it because my mob is a diamond, so the collisions wouldn't be right) LOVE errors and says "attempt to call method 'destroy' (a nil value)". I know you have to delete the shapes first, but it's just erroring.
Code: Select all
for k, v in pairs(bullets) do
for j, n in pairs(bullets) do
if dist(v.b:getX(), v.b:getY(), n.b:getX(), n.b:getY()) <= 2 then
n.s:destroy() --shape member of the bullets table
v.s:destroy() --same as above
n.b:destroy() --body member of the bullets table
v.b:destroy() --same as above
end
end
end