Help with collision detection bug

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
runyonave
Prole
Posts: 27
Joined: Tue Dec 06, 2011 2:06 am

Help with collision detection bug

Post by runyonave »

First of all, thanks to all those who helped with my previous question. I'm starting to understand Lua now, and currently working on creating a top down action RPG game. At the moment I have a test version for collision detection, but there is a problem with the player's bounding box. It seems the player bounding box is very much out of alignment with the player.

For a better description of the problem, I have attached the game.

Tiles with number 4 are walkable, while all other tiles block the player.

The collision detection is working fine, but the player's alignment with the blocks are off by 20 pixels in all directions.

Also in LOVE, when you create a new image and draw it, are the starting X and Y axis located in the top-left area of the box?

Another question: How do I create an array of a tileset.png file?
Attachments
runyonave_tile_engine.love
(55.23 KiB) Downloaded 179 times
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Help with collision detection bug

Post by osgeld »

at first glance your math is off .. when I add

Code: Select all

print(math.floor((topLeftX - 1)/20))
into the

Code: Select all

if direction == "left" then 
--check LEFTtop
block

the minimum value I get in the terminal is 2, though I have not looked enough to pinpoint why

I dont know how your doing it but I find it extremely helpful to run code under test from the command line, therefore you can dump debuging print statements to the standard-io without cluttering up the love window
Also in LOVE, when you create a new image and draw it, are the starting X and Y axis located in the top-left area of the box?
yes, at one time it was in the center of the image, which makes more noobie since but it was a bit of a pain in the arse as you had to offset all 4 sides appropriately when writing and it was voted to be changed quite a few versions ago
User avatar
runyonave
Prole
Posts: 27
Joined: Tue Dec 06, 2011 2:06 am

Re: Help with collision detection bug

Post by runyonave »

Yeah I'll have to look into that. Probably a problem with the array.

I'm currently using notepad++ so no debug window for me. I'm just going to download Scite and use that.

Didn't know the center point was used as the x,y axis before, that would have been really annoying.
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Help with collision detection bug

Post by osgeld »

where is love installed on your system? cause it does not really matter what editor your using (heck for core lua functions its not strange to me to use nano for linux or edit for ms-dos), the basic lua system is some form of text editor and a command line ... you could get complicated but I just install love at c:\love then set or make a cmd file where it points the path to that directory

path =c:\love

cd project_folder\project_name
love main.lua

on nix systems like I normally use its a bit different

love (folder_to_love_project)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Help with collision detection bug

Post by bartbes »

osgeld wrote: path =c:\love

cd project_folder\project_name
love main.lua
Filthy lies, this won't work.
You run it on the folder as well, and, you probably want to pass --console to the binary, so it opens up a debug window for you.
User avatar
runyonave
Prole
Posts: 27
Joined: Tue Dec 06, 2011 2:06 am

Re: Help with collision detection bug

Post by runyonave »

osgeld wrote:where is love installed on your system? cause it does not really matter what editor your using (heck for core lua functions its not strange to me to use nano for linux or edit for ms-dos), the basic lua system is some form of text editor and a command line ... you could get complicated but I just install love at c:\love then set or make a cmd file where it points the path to that directory

path =c:\love

cd project_folder\project_name
love main.lua

on nix systems like I normally use its a bit different

love (folder_to_love_project)
Love isn't really installed anywhere on my system. When I have a project, I just copy all the love files to the project folder. Then make a zip file. Then When I want to test the game, I just copy main.lua to the zip file, then drag the zip file to love .exe file.

I do need a debug console window though, that would make things much easier than using love.graphics.print all the time. Does Scite or another Lua IDE have this funtionality?

bartbes wrote:Filthy lies, this won't work.
You run it on the folder as well, and, you probably want to pass --console to the binary, so it opens up a debug window for you.
How do I edit the binary?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Help with collision detection bug

Post by tentus »

runyonave wrote: Love isn't really installed anywhere on my system. When I have a project, I just copy all the love files to the project folder. Then make a zip file. Then When I want to test the game, I just copy main.lua to the zip file, then drag the zip file to love .exe file.
Hoo, complicated. If you're using Notepad++, did you know that running your game can be as easy as hitting a keyboard combination? On my system I have it set up to ctrl+enter. All you have to do is put Love somewhere on your hard drive, set up a run command in Notepad++, and choose a key combo.

The run command should look something like this:

Code: Select all

"c:\your\path\to\love.exe" "$(CURRENT_DIRECTORY)"
What it actually does is load the current folder into Love, just as if you had dragged it onto the exe. Love runs it and everything is peaches and gravy.
Kurosuke needs beta testers
User avatar
runyonave
Prole
Posts: 27
Joined: Tue Dec 06, 2011 2:06 am

Re: Help with collision detection bug

Post by runyonave »

^ Is there any way to get a debug window on notepad++?

Edit: I set up Scite with Lua, set the lua.prperties in scite. Now it works fine, but the console in Scite is really slow.

For example if I press left and I want to know what the X position is, the console will only show this data after a few seconds, not instantly. That kind of makes it useless. Is there any other way I can see debugging data in a console?
User avatar
runyonave
Prole
Posts: 27
Joined: Tue Dec 06, 2011 2:06 am

Re: Help with collision detection bug

Post by runyonave »

Yess, I got the collision detection to finally work. There was a problem with one of my arrays.

I am not used to arrays starting at index 1, so I was ignoring it til I realised, 'oh wait, this is Lua! Indexes always start at 1'.

Ugh! Lua, why you no start at 0?

Anyway I attached the bug fixed version. Next, organize my code and add graphics.

Arrow keys to move, all tiles are blocked except for tiles with number 4.

Edit: I added some tiles to test it out.
Attachments
runyonave_tile.love
(56.49 KiB) Downloaded 208 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Help with collision detection bug

Post by bartbes »

For a debug window (as I mentioned), turn it into:

Code: Select all

"c:\your\path\to\love.exe" --console "$(CURRENT_DIRECTORY)"
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests