Trouble with multiple enemies
Posted: Fri May 15, 2020 5:46 am
Hi, I'm currently creating a platformer/rpg game to develop better skills with programming. My current issues is with multiple enemies, when I have one enemy spawned, everything works as intended, but if I spawn more than one, they start going nutty.
One enemy spawned I'm not sure where the problem lies, here is a snippet of my physics callbacks that may be the culprit.
Here is a copy of my .love file
I also have all this in a github for easy access
https://github.com/Sly-XP/Atom-Mobile
Any and all help/criticism/advice is appreciated, thanks!
One enemy spawned I'm not sure where the problem lies, here is a snippet of my physics callbacks that may be the culprit.
Code: Select all
function beginContact(a, b, coll)
x,y = coll:getNormal()
local userDataA = a:getUserData()
local userDataB = b:getUserData()
if userDataA == 'Platforms' and userDataB == 'player' then
player.grounded = true
end
if a:getUserData() then
if b:getUserData() then
if a:getUserData() == 'player' and b:getUserData() == 'enemy' then
for _, v in pairs(enemy) do
v.touchingPlayer = true
end
elseif a:getUserData() == 'Platforms' and b:getUserData() == 'enemy' then
for _, v in pairs(enemy) do
v.grounded = true
-- v.jumping = false
end
end
end
end
end
function endContact(a, b, coll)
x,y = coll:getNormal()
local userDataA = a:getUserData()
local userDataB = b:getUserData()
if userDataA == 'Platforms' and userDataB == 'player' then
player.grounded = false
end
if a:getUserData() then
if b:getUserData() then
if a:getUserData() == 'player' and b:getUserData() == 'enemy' then
for _, v in pairs(enemy) do
v.touchingPlayer = false
end
elseif a:getUserData() == 'Platforms' and b:getUserData() == 'enemy' then
for _, v in pairs(enemy) do
v.grounded = false
-- v.jumping = true
end
end
end
end
end
https://github.com/Sly-XP/Atom-Mobile
Any and all help/criticism/advice is appreciated, thanks!