Collision isn't working

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Collision isn't working

Post 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
Attachments
svl.love
(6.79 MiB) Downloaded 306 times
a² = b² + c²
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Collision isn't working

Post by davisdude »

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
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Re: Collision isn't working

Post by Autophoenix »

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²
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Collision isn't working

Post by davisdude »

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
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Re: Collision isn't working

Post by Autophoenix »

I've downloaded that and it worked. What is happening? Would you like an WinRAR file, instead of an love one.
a² = b² + c²
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Collision isn't working

Post 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.
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
User avatar
SneakySnake
Citizen
Posts: 94
Joined: Fri May 31, 2013 2:01 pm
Contact:

Re: Collision isn't working

Post by SneakySnake »

The problem is that the archive is a RAR archive. It should be a ZIP archive.
I attached a ZIP version.
Attachments
svl.love
(6.79 MiB) Downloaded 304 times
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Collision isn't working

Post by davisdude »

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
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Re: Collision isn't working

Post 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? :cry:
Last edited by Autophoenix on Wed Apr 16, 2014 6:47 pm, edited 1 time in total.
a² = b² + c²
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Re: Collision isn't working

Post by Autophoenix »

.love:
Attachments
svl.love
(6.79 MiB) Downloaded 317 times
a² = b² + c²
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests