How To Intergate Ammo.js Physics - Engine Only

Hi guys… i am trying to figure out how to implement physics engine so i can use the rigidbody component from code. But i cant seem to find any documentation on how to do so.

Now i understand you have an Online Editor for those extra tooling features, but you cannot really
be purpose withholding the information on how to integrate ammo.js into our Engine Only Projects.

Can you ?

There’s an example in the examples folder: https://github.com/playcanvas/engine/tree/master/examples/physics/falling_shapes

(Found it by searching for ‘physics’ in the git repo)

Dude I look all over the net and in forums…, never tried searching the repo… Thank dude… I will check it out immediately… thanks again :blush:

So from I can tell… to enable the physics engine, you include the ammo.js script and you enable or active physics using app.systems.rigidbody.setGravity

Is there no ‘enable physics’ function or does setting the gravity enable the physics engine ???

IIRC, just including the ammo.js script is enough. I think there is some code that checks for the existence of ammo on startup and if it does exist, then creates the ‘physics world’. Check RigidBodyComponentSystem in the engine.

setGravity sets the gravity, it doesn’t enable/disable the physics engine.

Hey Bro… Do you know how to make the collision volumes visible in the scene so I can see if it right size around mesh ?

Use the engine only? You will have to render them yourself.

What does that mean… Render my self… Render what… There is no info on the ENTIRE PLANET that tells me What i need to render to make a collider visible…

Are you saying i need to somehow MAGICALLY find the internals of your collision system, find the bound box for said collider and what… actually create ANOTHER separate mesh with visibility that is supposed to represent my collider…

Are saying there is know way for your engine to Visually represent the Bonding Box area of the collider…

And worst of all… With NO DOCS… How are we (Engine Only Developers) supposed to know how to do such things ???

I dont have much hair left… but CRAWLING the web All day and night looking FOR ANYHTING to help me write my PlayCanvas games is makeing me pull out the little hair i got left :slight_smile:

There’s nothing magical about it. The source code is open. Just pull it from a repo and search through it.

Nope. There is a mesh builder in PlayCanvas for cubes/cuboids, cylinders and sphere that you can create, scale to the correct size of the collider and attach it to the root of the scene.

The API is pretty well documented https://developer.playcanvas.com/en/api/ (generated from the engine source code comments). Most of the tutorials can mostly be used with the engine only as well. Additionally there are examples in the repo.

Ammo.js is a separate library (https://github.com/kripken/ammo.js/) which is a port of Bullet and you can find the documentation here: http://bulletphysics.org/Bullet/BulletFull/

You shouldn’t need to dive into it unless you are thinking of using features not exposed via the PlayCanvas API (such as joints).

In all seriousness, the source code is open. Start there.

Eg. Looking for how big the collider is:
You can get the height/half extents/radius of the collider volume here: https://developer.playcanvas.com/en/api/pc.CollisionComponent.html

Now the docs don’t show where the to get the rigid body position in the simulation as it’s not deemed to be public but because we are in Javascript, it’s all accessible anyway. So when you go through the engine source for this component, you can see it is given a ‘body’ which represents the rigid body in Ammo.js for the simulation: https://github.com/playcanvas/engine/blob/master/src/framework/components/rigid-body/component.js#L205

In syncEntityToBody: https://github.com/playcanvas/engine/blob/master/src/framework/components/rigid-body/component.js#L566 you can see how to get the position and orientation of the Ammo rigid body that you could use to position your representation.

1 Like

That’s what I’m saying… most other engines have some bonding box visualization for debugging your collider. But apparently in PlayCanvas you have to create some kind of proxy mesh at runtime and calculate out size if you want a visual representation…

My problem is, how would I know to that. Know I know, and now that I know , that’s no problem.
But it doesn’t say anywhere I have to do that for my colliders… as a matter a fact , it doesn’t say anything about colliders, but to add it in the editor

I’m just trying to explain where I’m coming from, Not trying to be A hole it appears I am on the forums

It’s not a feature of the engine to be able to render the collision volumes so why would it?

There’s a whole section on colliders and triggers here:
https://developer.playcanvas.com/en/tutorials/collision-and-triggers/
And using forces/impulses here:
https://developer.playcanvas.com/en/tutorials/Using-forces-on-rigid-bodies/

And all the editor is really doing is setting the attributes on the components of the rigid body and collision volumes.

Is there something about the engine that you haven’t grokked? I appreciate there is a component based framework on top of the rendering and physics which is perhaps abstracting any understanding.

I extended the fallingshapes example somewhat for glTF:

  • first-person-movement with collision based ground detection and jumping (WASD + Space)
  • some interactive buttons to drop more shapes + clean them up
  • example of how to integrate custom Ammo.js code which isn’t covered in PlayCanvas currently
  • simply drag&drop glTF models made in e.g. Blender and make them either static/dynamic via button
  • walk around on/in your glTF models/maps
  • easily debuggable via f12/devtools, just try editor.<scroll>

Just install e.g. XAMPP on Windows, clone https://github.com/playcanvas/playcanvas-gltf into C:\xampp\htdocs and open http://127.0.0.1/playcanvas-gltf (just saying, if somebody interested is reading this and doesn’t know it yet)

Sooner or later I hope there is a sane standard for glTF physics, but until then, nothing stops us to already implement lots of physics code which makes use of glTF. E.g. implement stuff like skeletonToRopes(), skeletonToConstraints(), meshToSoftBody() or whatever is needed.

1 Like

How can i include ammo.js into my project? my englist is poor,thank you

click add mesh or 3D object, make a cuboid entity, add physics > collision, it will prompt with “import ammo.js” click it, delete the cuboid if needed, or go into project settings > asset tasks (I think) and add ammo.js (it my be physics > “import ammo.js”)

The help is always appreciated, but this thread is 5 years old. No need to resurrect them.

1 Like

Oh sorry, I never seem to look at the dates but I will next time. Thank you.

1 Like