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
Collision isn't working
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Re: Collision isn't working
Looks like you uploaded your file incorrectly. I tried to unzip it, but the file was corrupted.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Re: Collision isn't working
The file is working. Execute the .bat file to directly open main.lua with love2d
- Attachments
-
- RunLOVE2DGame.rar
- (127 Bytes) Downloaded 310 times
a² = b² + c²
Re: Collision isn't working
Still isn't working.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Re: Collision isn't working
I've downloaded that and it worked. What is happening? Would you like an WinRAR file, instead of an love one.
a² = b² + c²
Re: Collision isn't working
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.
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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- SneakySnake
- Citizen
- Posts: 94
- Joined: Fri May 31, 2013 2:01 pm
- Contact:
Re: Collision isn't working
The problem is that the archive is a RAR archive. It should be a ZIP archive.
I attached a ZIP version.
I attached a ZIP version.
- Attachments
-
- svl.love
- (6.79 MiB) Downloaded 304 times
Re: Collision isn't working
It still isn't working for me.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Re: Collision isn't working
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:
They are the wrench X, Y and its rotation.
In scripts/enemies/spycrab.lua I got:
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:
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?
In scripts/player.lua I got these variables:
Code: Select all
wr = {}
wr.positionsX = {}
wr.positionsY = {}
wr.rotations = {}
In scripts/enemies/spycrab.lua I got:
Code: Select all
sc = {}
sc.X = {}
sc.Y = {}
sc.Rot = {}
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
Can someone throw me a light?
Last edited by Autophoenix on Wed Apr 16, 2014 6:47 pm, edited 1 time in total.
a² = b² + c²
- Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Re: Collision isn't working
.love:
- Attachments
-
- svl.love
- (6.79 MiB) Downloaded 317 times
a² = b² + c²
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests