Body.blocked not working at low fps

It seems that phaser’s body.blocked variable doesn’t work consistently when my game is running at around 30 fps or lower. When I run against a wall, my player.body.blocked.left or right variable either doesn’t get set to true, or changes rapidly from true to false. It doesn’t affect me when playing on my desktop, but my slower laptop has major problems. I made an example game to show this:

60 fps:
60
blocked works as intended

~30 fps:
30
blocked flashes on and off

~20 fps:
20
blocked only turns true for one frame every few times I hit the wall

Edit: I can’t figure out how to paste the code without it taking up the whole post so here’s the game’s files.

Is there any fix for this?

In a lot of cases I think flipping back and forth is normal because it’s the result of separation after the collision. I’m not sure about the low-FPS case.

Hi @MusicMan,
I was able to reproduce the problem with physics.world.setFPS().

See the Pen [Phaser 3] physics FPS &rt; render FPS by Juan Jose Capellan (@jjcapellan) on CodePen.

If the fps of the physical simulation are much higher than the fps of the render, then between rendered frames more things happen than we can see on the screen.
But I guess a callback in the collision should work.

Regards.

Thanks so much @jjcapellan, this stumped me for a few days.

I was experiencing a similar issue with a static group of colliders. When my battery was low / device was overloaded these would all be ignored, setting:

fps: {
        target: 60,
        forceSetTimeOut: true,
    }

in my config solved the issue for me.

1 Like

Phaser can’t force a minimum FPS, and some devices reduce FPS in low-energy mode.

I think the blocked inconsistency problem has been solved in Phaser for a while, and I don’t see the problem now.

For some applications you may want to try the WORLD_STEP event instead of update().