collision issues
Posted: Wed Sep 19, 2012 11:32 am
Right, so, i've grabbed the collision callbacks tutorial (https://love2d.org/wiki/Tutorial:Physic ... nCallbacks) and i've been using the entity system goature explains in his tutorials (http://www.youtube.com/playlist?list=PL924F20B05A624D91)
Now, i admit i've probably somewhat fudged things a bit (using the setPos function to fire arguements into the entities i create probably isnt the slickest solution, but i was in a bad mood).
Problem i'm having is, after a while, my enemy entities seem to stop reacting to collision hits. The callback function seems to be recieving them though... I'm obviously doing something stupid, so i figured i'd ask if there are any particular tutorials on this kind of stuff? Or if there's someone out there with the time and patience to give me a hand, i wouldnt complain
Here's how I'm trying to grab the collisions from the world callbacks...
and in the enemy entity...
Now, i admit i've probably somewhat fudged things a bit (using the setPos function to fire arguements into the entities i create probably isnt the slickest solution, but i was in a bad mood).
Problem i'm having is, after a while, my enemy entities seem to stop reacting to collision hits. The callback function seems to be recieving them though... I'm obviously doing something stupid, so i figured i'd ask if there are any particular tutorials on this kind of stuff? Or if there's someone out there with the time and patience to give me a hand, i wouldnt complain
Here's how I'm trying to grab the collisions from the world callbacks...
Code: Select all
function beginContact(a, b, coll)
x,y = coll:getNormal()
for i, ent in pairs(ents.objects) do
if ent.fixture:getUserData() == a:getUserData() then
ent.colliding = b:getUserData()
elseif ent.fixture:getUserData() == b:getUserData() then
ent.colliding = a:getUserData()
end
end
end
Code: Select all
function ent:update_collision()
for i, ent in pairs(ents.objects) do
if ent.fixture:getUserData() == self.colliding then
if ent.colliding then
print("-------------------------------------------------------------------------------")
print (ent.fixture:getUserData(), ent.colliding)
end
if ent.type == "fireball" then -- was i hit by a fireball?
self:damage (ent.dam)
end
if ent.type == "fireball_exp" then -- was i hit my a fireball explosion?
self:damage (ent.dam)
if ent.cast_time > 0.5 then
if self.health > 0 then
local hit_force = 100000 * ent.cast_time
if ent.cast_time == 1 then
hit_force = 150000
end
repel_object(ent, self, hit_force)
self.exp_hit = true
end
end
end
if self.health > 0 then
if ent.type == "icenova" then --was i frozen?
self.frozen = true
end
end
end
end
end