[SOLVED] Slow physics and other issues

First of all, I love playcanvas and the community, and ofc the dev team behind it!

i think its quite clear that the physics intengrated in this engine just doesnt really work, especially if there are a lot of rigidbodies, or if rigidbody.teleport is being called on a number of rigidbodies.

If the rigidbody collides with a triangle on a mesh collider, it also just falls through. It surely is unnacceptable and we cant honestly expect many complicated games to come out of this.

I get that p2.js has been suggested in the past but again a 2d physics engine(even if it is playing out on a x and z axis) cannot really do everything we need it to.

At this point I am stuck with moving away from ammo and onto oimo or something similar, this again is not ideal since as game developers we don’t want to keep building every single frame work while the world outside is moving forward with better games and more tech.

I will however say that it is CLOSE. Just need some real solutions, if oimo.js is it, then so be it, but where are the plugins or documentations based around how this externally integrated physics would work ?

I’ve done some basic benchmarking a while ago between ammo.js, oimo.js and cannon.js with lots of rigid bodies and they all suffer in performance at around the same number of rigid bodies in a scene (lots of 1m cubes).

The main problem is this is still being ran on a single thread. The physics could be ran on a web worker, taking advantage of multi core processors and I think it is now widely supported.

I haven’t yet come across this issue. Is either body moving at high speed? If so, it would be worth enabling CCD on the fast moving object so it doesn’t go through another body.

Is teleport being called every frame?

1 Like

I’ve done some basic benchmarking a while ago between ammo.js, oimo.js and cannon.js with lots of rigid bodies and they all suffer in performance at around the same number of rigid bodies in a scene (lots of 1m cubes).

Do you have any projects with this Benchmarking? Would be interesting to see in general how to attach playcanvas to another physics engine apart from ammo.

I haven’t yet come across this issue. Is either body moving at high speed? If so, it would be worth enabling CCD on the fast moving object so it doesn’t go through another body.

Yes this is a rigidbody moving towards and colliding into part of a terrain for example. Its been mentioned a few times in numerous threads. The suggestion in the past has been to further edit the model to cater to this but cant always do that especially in generated terrains.
Would other physics libs have the same issue?

I literally only implemented the cube rigidbody in these samples:
https://playcanvas.com/project/446362/overview/ammo-physics-test
https://playcanvas.com/project/447531/overview/cannon-physics-test
https://playcanvas.com/project/447510/overview/oimo-physics-test

Could you provide an example please just to make sure the issue I’m thinking off is the same issue? A video will do in lieu of the project.

1 Like

You may need to fork these projects to get them to work for some reason :thinking:?

Why can’t we make ammo work as webWorker, by the way?..

We can. We just haven’t got around to it yet. It’s quite a significant job to implement that. Before that, I’d probably add support for the WASM build of Ammo:

Nice, it would be great!

Is it really hard to implement? Maybe we can help with that?

You’re welcome to, yes, that’d be great. I guess the main thread would just have to communicate instructions to the worker (set gravity, create rigidbody, set mass, etc) and the worker would have to send the simulation state back to the main thread every frame (updated transforms).

For us to update to use WASM, we’d have to change how published apps load Ammo - in other words, we’d have to update the Editor as well as the Engine.

I got it.

But still, we can run WebWorker with compiled Ammo as well, right?
To kill two birds with one stone?

I believe so, yep. :bird::bird:

1 Like

@yaustar the tests are dead (errors when running) , could you please revive them? specially interested on the cannon version

Late reply, I completely forgot about this:

Updated Ammo using WASM: https://playcanvas.com/project/679181/overview/cannon-physics-test
Fixed Cannon: https://playcanvas.com/project/679181/overview/cannon-physics-test

1 Like

Thanks :slight_smile:

@yaustar
Did you ever consider testing PhysX? It’s the physics engine Unity and Unreal Engine use and Javascript ports do appear to exist: https://www.npmjs.com/package/physx-js

It didn’t come up at the time when I originally did those tests. Also didn’t realise PhysX is now open source :thinking:

PhysX is a really good option, and I feel we should try it out. And it’s not entirely open source, like something with the MIT license - copyright of NVIDIA must still be mentioned explicitly(https://github.com/NVIDIAGameWorks/PhysX).

Somebody did submit a WASM build target to that repo:

But they haven’t merged it yet. When they do, we could build the library and add it to the PlayCanvas Store, alongside ammo.js.

3 Likes

That’d be great @will.

2 Likes