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
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
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
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.
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:
And using forces/impulses here:
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
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
meshToSoftBody() or whatever is needed.
How can i include ammo.js into my project? my englist is poor,thank you