Page 1 of 1

How to optimize hardoncollider collision checks?

Posted: Wed Apr 04, 2012 2:16 pm
by MiniDemonic
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.

Re: How to optimize hardoncollider collision checks?

Posted: Wed Apr 04, 2012 11:45 pm
by Refpeuk
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! ;)

Re: How to optimize hardoncollider collision checks?

Posted: Thu Apr 05, 2012 12:47 am
by MiniDemonic
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 :)

Re: How to optimize hardoncollider collision checks?

Posted: Thu Apr 05, 2012 9:29 am
by vrld
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 3447 times
Solving this situation is actually a very hard problem. Searching for box stacking problem might give you some insight.

Re: How to optimize hardoncollider collision checks?

Posted: Fri Apr 06, 2012 1:11 am
by MiniDemonic
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.