How to optimize hardoncollider collision checks?

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
MiniDemonic
Prole
Posts: 28
Joined: Tue Mar 20, 2012 10:39 am

How to optimize hardoncollider collision checks?

Post by MiniDemonic » Wed Apr 04, 2012 2:16 pm

Well another problem appeared when I tried to optimize the FPS in my zombie game.
Instead of doing "z:collidesWith(whatever)" in the zombie_update code, I switched to doing the zombie collision checks using "on_collision", I did that because it significantly raised my FPS. But! I don't know how to fix the flickering problem that the zombies now suffer from, those poor creatures.

Controls
w,a,s,d = move
mouse = aim and shoot
z = spawn zombie roughly at mouse (haven't bothered to update spawn code when I added the camera)
F1 = start game

Spawn a few zombies so that they surround you and then move around, you will see that their movement flickers.

the lua files you probably want to look at are:
zombie.lua
game.lua

Thanks in advance.
Attachments
Zombehs!1.love
(602.02 KiB) Downloaded 91 times
Last edited by MiniDemonic on Thu Apr 05, 2012 12:47 am, edited 1 time in total.

User avatar
Refpeuk
Citizen
Posts: 91
Joined: Wed Dec 14, 2011 6:16 pm

Re: How to optimize hardoncollider collision checks?

Post by Refpeuk » Wed Apr 04, 2012 11:45 pm

Hmm, I can't seem to get past your menu, clicking on the buttons has no effect, nor does using arrow keys, wasd, enter, or space.

Nevertheless you may want to make sure you are not solving multiple collisions per frame; that was a problem I had before. Happened because I collided with two objects that had the exact same value on one plane, so it hit both at the same time and solved double the mtv. I don't know if that's your issue, since I can't run your game. Menu looks nice though! ;)
It was the best of times, it was the worst of times . . .

MiniDemonic
Prole
Posts: 28
Joined: Tue Mar 20, 2012 10:39 am

Re: How to optimize hardoncollider collision checks?

Post by MiniDemonic » Thu Apr 05, 2012 12:47 am

Refpeuk wrote:Hmm, I can't seem to get past your menu, clicking on the buttons has no effect, nor does using arrow keys, wasd, enter, or space.

Nevertheless you may want to make sure you are not solving multiple collisions per frame; that was a problem I had before. Happened because I collided with two objects that had the exact same value on one plane, so it hit both at the same time and solved double the mtv. I don't know if that's your issue, since I can't run your game. Menu looks nice though! ;)
Oh yea, forgot to write that in the OP, to start the game you need to press f1, haven't coded the menu buttons yet hehe :)

User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: How to optimize hardoncollider collision checks?

Post by vrld » Thu Apr 05, 2012 9:29 am

The problem is indeed collision resolution. When there are many zombies around the player and you move one shape to resolve a collision, you are introducing a new collision. That new collision will be detected in the next frame, where the circle repeats. Let me illustrate:
zombies.png
zombies.png (63.56 KiB) Viewed 905 times
Solving this situation is actually a very hard problem. Searching for box stacking problem might give you some insight.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

MiniDemonic
Prole
Posts: 28
Joined: Tue Mar 20, 2012 10:39 am

Re: How to optimize hardoncollider collision checks?

Post by MiniDemonic » Fri Apr 06, 2012 1:11 am

Thanks vrld, once again.
You have helped my so much that I will include you in the credits for the game when I release it.

The game is not designed to have zombies stacked, and this problem seems too hard to solve to even care about it.
I will update the main thread for this game as much as possible. You can find it in projects and demos.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests