2D scroller collision [help]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
hally
Prole
Posts: 7
Joined: Fri Nov 23, 2012 3:02 am

2D scroller collision [help]

Post by hally »

Hi i am working on a project for school and need help with my collision i have it written but it give the error "attempt to index field '?' (a nil value). Have had a slight look at it and tried to research it but to no prevail, your help would be great :awesome: :awesome: :x
Attachments
Love game zip.zip
This is the game zipped could not put it as a .love as i am at school (limmited access to file modification)
(16.11 KiB) Downloaded 113 times
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: 2D scroller collision [help]

Post by Qcode »

Welcome to the forum!
Your collision still isn't working, but I've fixed the error you've been getting. What you were doing was accessing the table by the player x and y. The problem was however, that your map table didn't include tiles for every single pixel on the screen, which it shouldn't. So to fix this you would get the tile that the players coordinates were on. So you would replace line 121 with:

Code: Select all

if map[math.floor(player.y/16)  + y][math.floor(player.x/16)  + x] == 1 then
The 16 is because you have tiles with width and height of 16.
That'll fix your error.
Hope that helps.
~Qcode
P.S Also next time you should post requests for help in the Support and Development forum, not general.
hally
Prole
Posts: 7
Joined: Fri Nov 23, 2012 3:02 am

Re: 2D scroller collision [help]

Post by hally »

Oh thanks lol that took me like a couple of seconds to look and then i noticed what you where talking about would have had no clue if you didn't help thank for the help :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests