2D scroller collision [help]
2D scroller collision [help]
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
- 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 112 times
Re: 2D scroller collision [help]
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:
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.
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
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.
Re: 2D scroller collision [help]
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
Who is online
Users browsing this forum: No registered users and 4 guests