With Platypus I have issues, that I still can’t fix - when switching focus from the game windows/browser tab, when I get back the character is falling down through the collision shapes.
Sometimes it happens also in the beginning. But not always. I suspect that collisions are not ready yet and raycast is not working, but the update is still lowering the position of game object
It is not happening with Platypus example, and I guess my level is too big or post-process is too heavy. Though, I optimised it a lot, the game hangs for a while anyway when switching focus back and the issue with falling down happens.
Why do you think is happening?
What can I do to prevent it?
At start:
Switching windows (build from Editor, the same happens with Windows build and HTML5 build):
Focus was on another windows when started - switching back:
What are your vsync and frame cap settings? It might be that the physics skip frames and that’s why you’re seeing this behaviour. I’ve noticed this happening when vsync is disabled.
Wow! It really works! I have indeed disabled Vsync and just enabled it and was trying for a while to reproduce it, but it never happened! In Platypus example Vsync is also enabled (like in default game.project)
My workaround is to disable dynamic collision objects in the scene’s init method, and then turn them on after a while.
To solve bugs with physics after window switching I pause the physics world by setting the timestep to zero on the focus lost event and set it back to 1 on the focus gained event.
function on_window_event(self, event, data)
if event = window.WINDOW_EVENT_FOCUS_LOST then
msg.post("#gameproxy", "set_time_step", { factor = 0, mode = 1 })
elseif event == window.WINDOW_EVENT_FOCUS_GAINED then
msg.post("#gameproxy", "set_time_step", { factor = 1, mode = 1 })
end
end
function init(self)
window.set_listener(on_window_event)
end