Today I am glad to show you my little experiment with physics and PlayCanvas.
As you might know, PlayCanvas uses bullet’s port Ammo.js for physics calculation.
The problem is, it calculates in main thread with graphics render.
So it means that every frame you have to wait until physics and graphics is done.
When your scene is complex it can causes glitches if your computes isn’t powerful enough.
But I am working on solution for this problem. And it’s name is WebWorker.
What is it?
WebWorker allows us to calculate physics in a separated thread. So you don’t have to wait until physics is done, only graphics render.
How can it help your game?
When your game has a lot of complex meshes, you need more time to render it. With WebWorker you have more time, because you don’t need to wait for physics every frame!
When your game has a lot of rigid bodies, your scene doesn’t lock to wait until it’s calculated. Yes, it lags, but your game is not!
Which advantages does it give?
You can have either more complex meshes and rigid bodies with stable FPS or more difficult physics calculations the with the same framerate.
How can I see the difference?
There is a scene with 1000 cubes.
(Works only in major browsers such a Google Chrome)
You can rotate your camera to see that your render is not locking because of difficult physics calculations (unless you have a really low performance)
Separated physics is a good approach for web game development.
Will PlayCanvas implement it?
I don’t know. Probably one day. I would be so happy then.
I also hope somebody from core team leave a comment here.