Help with optimizing collision detection [FIXED]

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.
Post Reply
TheLivingTree
Prole
Posts: 5
Joined: Thu Jul 24, 2014 12:06 am

Help with optimizing collision detection [FIXED]

Post by TheLivingTree »

Hello Lovers,

I know a lot of problems regarding collision detection have been posted on this forum before but I believe mine is unique and a little more involved. I am using the HardonCollider Library for my collision detection when I noticed a problem. Sometimes the entities would sink through the floor. The problem gets worse when more entities are introduced but still occurs when there's only one entity. I have narrowed it down and found only entities smaller than the tile size (16x16) fall through. I cannot be the only person out there who has run into this issue. Is there anyway to optimize the HardonCollider or do any of you know of an article that may be helpful?

Here is how I am instantiating the HardonCollider.

Code: Select all

collider = HC(10, on_collide, on_stop_collide) --in love.load
Thank you in advance!

Also I have included a .love of the game so far so you can see the issue firsthand
Controls:
'WASD' controls movement
'q' adds another entity (currently no way to remove entities so just restart the game)
'r' resets position of all entities
'move mouse' moves camera
'scroll wheel' zooms camera
'up and down' changes scale of entities

Other important information:
When the ground changes to pink that means an entity is grounded (Best noticed with one entity)
Attachments
Collision Problem.love
(248.51 KiB) Downloaded 185 times
Last edited by TheLivingTree on Fri Oct 31, 2014 3:23 am, edited 1 time in total.
hmans
Prole
Posts: 4
Joined: Thu Oct 23, 2014 3:20 pm
Location: Hamburg, Germany
Contact:

Re: Help with optimizing collision detection (Please Read)

Post by hmans »

Hey there,

I've only been LÖVE'ing for a couple of days, I know nothing about the HardonCollider library, and I have not looked at your code yet, so I'm probably not qualified to answer, _but_ I know that issues like these are often caused by the game simply running too slow -- with fewer FPS, your update delta times get larger, so entities move farther within a single step, possibly moving past anything they could collide with.

(On my system, your game is running at a perfectly smooth 60 FPS, possibly more?, and the issue you're describing is not occuring.)

HTH
TheLivingTree
Prole
Posts: 5
Joined: Thu Jul 24, 2014 12:06 am

Re: Help with optimizing collision detection (Please Read)

Post by TheLivingTree »

hmans wrote:Hey there,

I've only been LÖVE'ing for a couple of days, I know nothing about the HardonCollider library, and I have not looked at your code yet, so I'm probably not qualified to answer, _but_ I know that issues like these are often caused by the game simply running too slow -- with fewer FPS, your update delta times get larger, so entities move farther within a single step, possibly moving past anything they could collide with.

(On my system, your game is running at a perfectly smooth 60 FPS, possibly more?, and the issue you're describing is not occuring.)

HTH
Thanks for the reply!

I do not believe it is an FPS issue because my computer runs it at a smooth 60 Frames. But that could be a potential issue for slower computers I had no thought of. The issue seems to occur when falling from a greater height. Try pressing 'r' to reset the entities positions so that they fall from a greater height, and also pressing the 'down arrow' which makes the creatures smaller will increase the error.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Help with optimizing collision detection (Please Read)

Post by s-ol »

If it's not an FPS issue, it's still the same issue that happens: the things move so fast that in one frame The haven't touched the surface and in the next they are past it.
There has to be a parameter somewhere in HardonCollider that controls how far you can move into another body and still be pushed out again.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
TheLivingTree
Prole
Posts: 5
Joined: Thu Jul 24, 2014 12:06 am

Re: Help with optimizing collision detection (Please Read)

Post by TheLivingTree »

Fixed!! Not the cleanest way but its a start. I will look into a parameter somewhere in the HardonCollider. Anyways, what I did was to extrude the sides of the shapes not facing outward (for example if a shape collides both top and bottom then expand the right and left sides) This causes the shapes to overlap adding a buffer for collision. At first this created a ton of lag (each collision between the tile was being calculated) but once I set all the tiles to passive the performance increased greatly!! So, while I'm not super happy about this solution its a start for now.

Thank you all lovians!!
Post Reply

Who is online

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