while self.myUpdateTicker > self.myTickTime do
self.myUpdateTicker = self.myUpdateTicker - self.myTickTime
for i, object in ipairs(self.myActiveObjects) do
object:OnUpdate(self.myTickTime)
self:HandleCollisionsForObject(object, i)
if object.myRemovalFlag then
table.insert(toRemove, object.myID)
end
end
end

However, if the framerate dips too low, this leads to a feedback loop where the collision is run so many times it slows down the framerate further (though I have a lower cap at 10fps).

I've tried moving the Collision code to outside the while loop, but that results in weird behaviour, with objects moving through walls.

Share this post

Link to post

Share on other sites

That would probably work, though as far as I can see that will only make it so collision is never updated more often than the cap, it doesn't make up for a lower framerate.
My collision is supposed to be able to handle environmental collisions regardless of framerate though, but right now it's a bit bugged. I'll try to fix it, then try it your way, thanks.

0

Share this post

Link to post

Share on other sites

That would probably work, though as far as I can see that will only make it so collision is never updated more often than the cap, it doesn't make up for a lower framerate.
My collision is supposed to be able to handle environmental collisions regardless of framerate though, but right now it's a bit bugged. I'll try to fix it, then try it your way, thanks.

If you use a time based approach, then it would work with lower frame rates. You basically have two options: time based, or frame-based. So, you would have to chose one and go with it.

Time based will ensure that if your frame rate goes to 10fps (your game will be unplayable at this level anyway) it will still run collision checks after the time base passed -- this is the best solution.

A frame based option is good too, but if you are running at 200 fps, that would mean the game is wasting time on collision checks that it could skip because the frame rate is so high.
The frame based option will back off when the game is running slow, So if your game is running at 10 fps, you will do few collision checks.

0

Share this post

Link to post

Share on other sites

Time based will ensure that if your frame rate goes to 10fps (your game will be unplayable at this level anyway) it will still run collision checks after the time base passed -- this is the best solution.

I'm not sure I get it.
If I make it so the game will check for collisions every 1/60 second, and the game starts running at 10fps, with the code you posted, won't it just check it once, then wait until the next frame to check again? That means I'll miss some checks whenever the framerate gets lower than 60fps.

Though I guess since this is my bottleneck I can't really do it any other way.