Page 1 of 2
Collision isn't working
Posted: Tue Apr 15, 2014 5:07 pm
by Autophoenix
In my game, when the player throws an wrench and it colides with the enemy, it should die. But, i don't know why, sometimes when i throw an wrench, the game gives me an error 'Attempt to perform arithmetic on a nil value'.
And, can I make a better collision?
PS: The error is in the file scripts/enemies/spycrab.lua
Re: Collision isn't working
Posted: Tue Apr 15, 2014 6:14 pm
by davisdude
Looks like you uploaded your file incorrectly. I tried to unzip it, but the file was corrupted.
Re: Collision isn't working
Posted: Tue Apr 15, 2014 8:06 pm
by Autophoenix
The file is working. Execute the .bat file to directly open main.lua with love2d
Re: Collision isn't working
Posted: Tue Apr 15, 2014 8:36 pm
by davisdude
Still isn't working.
Re: Collision isn't working
Posted: Tue Apr 15, 2014 8:40 pm
by Autophoenix
I've downloaded that and it worked. What is happening? Would you like an WinRAR file, instead of an love one.
Re: Collision isn't working
Posted: Tue Apr 15, 2014 8:47 pm
by davisdude
When I try to execute the .love alone, I get a no-game screen.
When I try to execute the .bat alone, I get "incorrectly packaged error".
When I try to drag the .love on to the .bat, it's still packaged incorrectly.
A .rar file with the .love inside wouldn't hurt.
Re: Collision isn't working
Posted: Tue Apr 15, 2014 10:19 pm
by SneakySnake
The problem is that the archive is a RAR archive. It should be a ZIP archive.
I attached a ZIP version.
Re: Collision isn't working
Posted: Wed Apr 16, 2014 12:32 am
by davisdude
It still isn't working for me.
Re: Collision isn't working
Posted: Wed Apr 16, 2014 4:45 pm
by Autophoenix
Ok now I've already fixed it.. but the problem is that when I have multiple wrenches at the screen, most of the time the wrench don't kill the enemy. I'm really pissed off about these errors.
In scripts/player.lua I got these variables:
Code: Select all
wr = {}
wr.positionsX = {}
wr.positionsY = {}
wr.rotations = {}
They are the wrench X, Y and its rotation.
In scripts/enemies/spycrab.lua I got:
Code: Select all
sc = {}
sc.X = {}
sc.Y = {}
sc.Rot = {}
It's the same thing as the wrench positions.
In spycrab_update(dt) is the code that checks if an wrench collides with the player:
Code: Select all
if #sc.X ~= 0 and #wr.positionsX ~= 0 then
for n = 1, #sc.X do
if n > #wr.positionsX then break else
if wr.positionsX[n]+wrench:getWidth() > sc.X[n] and wr.positionsX[n] < sc.X[n]+spycrab:getWidth() and wr.positionsY[n]+(wrench:getHeight()/2) > sc.Y[n] and wr.positionsY[n]+(wrench:getHeight()/2) < sc.Y[n]+spycrab:getHeight() then
table.remove(wr.positionsX, n)
table.remove(wr.positionsY, n)
table.remove(wr.rotations, n)
nadd = nadd - 1
table.remove(sc.X, n)
table.remove(sc.Y, n)
table.remove(sc.Rot, n)
scAdd = scAdd - 1
return #sc.X, #wr.positionsX
end
end
end
end
I've already tryied put 'break' instead of 'return #sc.X, #wr.positionsX', but when I have multiple wrenches at the screen, the program breaks the loop.
Can someone throw me a light?
Re: Collision isn't working
Posted: Wed Apr 16, 2014 6:18 pm
by Autophoenix
.love: