In the attached .love you will see my current problem. My on_collide collision detection function works fine for certain shapes (the walls of the arena) but not for others (the circle, called enemy). I've found out that it works inconsistently. Collisions are handled fine as long as the player is shape_a, but the player will get stuck and jitter if it is shape_b. Strangely, this only seems to happen when colliding with the enemy, not the walls, and happens inconsistently when starting the program.
Is this something I just need to account for in my code? I've attempted to do this but it isn't working. I was also experiencing tunneling through the walls previously, but it seems to have fixed itself and I can't get that to happen any more. What am I missing? Are there any more clear examples I can look at?
EDIT: Here's the collision function:
Code: Select all
local function on_collide(dt, shape_a, shape_b, mtv_x, mtv_y) -- mtv is 'minimum translation vector' needed to resolve the collision
local other
if shape_a == Game.player.shape then
other = shape_b
shape_a:move(mtv_x, mtv_y)
print('AAAAAAAAAAAAAAA')
elseif shape_b == Game.player.shape then
other = shape_a
shape_b:move(mtv_x, mtv_y)
print('BBBBBBBBBB')
else
return
end
if other == Game.enemy then
print('enemy')
end
print('bump')
--Game.player.shape:move(mtv_x, mtv_y)
Game.player.speed = 0
end