AMMO.JS Collision Response And Filtering

Hey guys… Especially you @trevordev

In cannon.js i was using the executeNativeFunction to setup the physics body with some extra stuff like:

 // Enable collisions or allow to pass thru
 body.collisionResponse = collisions;

// Setup collision group filtering
body.collisionFilterGroup = collisionFilterGroup;
body.collisionFilterMask = collisionFilterMask;

My question is how do i do those same two things (Collision Response and Filtering) using Ammo.js

– Thanks For Any Help :slight_smile:

Do you have a playground showing how it works in cannon. I am unfamiliar with these and am not yet sure if ammo supports the same features.

Hi guys. If I may slide-in an AmmoJS testing playground…

(thanks to @JohnK/others… for initial playground)

See console. Line 124 reports undefined. (yawn)

Line 125 reports an object… difficult to “browse” for me, so far. I don’t do object-inspecting very well… for these a.prototype.b.c.lotsOfMembers objects.

Just possibly… a unique collision-config needs setting, and then the collision masks/groups… will work.
Anyway, we have a testing playground… maybe. :slight_smile:

Those properties definitely exist in Ammo. :slight_smile: Party on, gang. I hope I have helped.

Thanks @Wingnut

Yo @trevordev … It looks ammo DOES support collision filter and mask… But i just dont see where to setup that stuff in executeNativeFunction.

Also… In cannon the collisionResponse = false will tell engine NOT TO COLLIDE, JUST PASS THRU… Is great for setting “TRIGGERS”

I found this on stack overflow:
In ammo.js this is solved by setting the collision flag “no_contact_response” or by using so called “ghost bodys” as triggers

But i have no idea how i would set “no_contact_response” flag either.

Can you please help with setting no contact response flag and setting up collision filter groups in ammo.js

Again @trevordev thank for all help… The new babylon toolkit is shaping up great :slight_smile:

Yo @trevordev and @Wingnut … Thanks so much guys for your help.

I managed to support TRIGGERS and CONSTRAINTS for physics with the new toolkit.

FYI … Here is how i am doing that:


Yo @trevordev and @Wingnut check out a better rigidbody unity export setup function using the native Ammo.js API … NOTE: I still need your help with collision groups and Masks :slight_smile:

        /** Setup native physics impostor function for the specified entity. Internal use only */
        private static SetupNativePhysicsFunction(scene:BABYLON.Scene, entity: BABYLON.AbstractMesh, child:boolean, trigger:boolean, rigidbody:any, debugging:boolean):void {
            if (entity.physicsImpostor != null) {
                entity.physicsImpostor.executeNativeFunction((word:any, body:any) => {
                    console.log("===> Setup Native Physics Body: " +;
                    // ..
                    // Disable Gravity
                    // ..
                    let gravity:boolean = (rigidbody != null && rigidbody.gravity != null) ? rigidbody.gravity : true;
                    if (gravity === false) {
                        if (body.setGravity) {
                            body.setGravity(new Ammo.btVector3(0.0, 0.0, 0.0));
                        } else {
                            BABYLON.Tools.Warn("Physics engine set gravity override not supported for: " +;
                    // ..
                    // Setup Drag Damping
                    // ..
                    if (body.setDamping) {
                        const ldrag:number = (rigidbody != null && rigidbody.ldrag != null) ? rigidbody.ldrag : 0.0;
                        const adrag:number = (rigidbody != null && rigidbody.adrag != null) ? rigidbody.adrag : 0.05;
                        body.setDamping(ldrag, adrag);
                        console.log("===> Setting drag damping for: " +;
                    } else {
                        BABYLON.Tools.Warn("Physics engine set drag damping not supported for: " +;
                    // ..
                    // Setup Collision Flags
                    // ..
                    let kinematic:boolean = (rigidbody != null && rigidbody.kinematic != null) ? rigidbody.kinematic : false;
                    if (child === true) kinematic = false;
                    if (body.setCollisionFlags && body.getCollisionFlags) {
                        if (trigger === true && kinematic === true) body.setCollisionFlags(body.getCollisionFlags() | BABYLON.CollisionFlags.CF_NO_CONTACT_RESPONSE | BABYLON.CollisionFlags.CF_KINEMATIC_OBJECT);
                        else if (trigger === true && kinematic === false) body.setCollisionFlags(body.getCollisionFlags() | BABYLON.CollisionFlags.CF_NO_CONTACT_RESPONSE);
                        else if (trigger === false && kinematic === true) body.setCollisionFlags(body.getCollisionFlags() | BABYLON.CollisionFlags.CF_KINEMATIC_OBJECT);
                    } else {
                        BABYLON.Tools.Warn("Physics engine set collision flags not supported for: " +;
                    // ..
                    // Setup Freeze Constraints
                    // ..
                    const freeze:any = (rigidbody != null && rigidbody.freeze != null) ? rigidbody.freeze : null;
                    if (freeze != null) {
                        if (body.setLinearFactor) {
                            const freeze_pos_x:number = (freeze.hasOwnProperty("positionx") && freeze.positionx === true) ? 0 : 1;
                            const freeze_pos_y:number = (freeze.hasOwnProperty("positiony") && freeze.positiony === true) ? 0 : 1;
                            const freeze_pos_z:number = (freeze.hasOwnProperty("positionz") && freeze.positionz === true) ? 0 : 1;
                            body.setLinearFactor(new Ammo.btVector3(freeze_pos_x, freeze_pos_y, freeze_pos_z));
                        } else {
                            BABYLON.Tools.Warn("Physics engine set linear factor not supported for: " +;
                        if (body.setAngularFactor) {
                            const freeze_rot_x:number = (freeze.hasOwnProperty("rotationx") && freeze.rotationx === true) ? 0 : 1;
                            const freeze_rot_y:number = (freeze.hasOwnProperty("rotationy") && freeze.rotationy === true) ? 0 : 1;
                            const freeze_rot_z:number = (freeze.hasOwnProperty("rotationz") && freeze.rotationz === true) ? 0 : 1;
                            body.setAngularFactor(new Ammo.btVector3(freeze_rot_x, freeze_rot_y, freeze_rot_z));
                        } else {
                            BABYLON.Tools.Warn("Physics engine set angular factor not supported for: " +;
                if (debugging === true) BABYLON.SceneManager.ShowDebugPhysicsImpostor(scene, entity);
            } else {
                BABYLON.Tools.Warn("No valid physics impostor to setup for " +;

If you can PLEASE still help me figure out what and how to use Ammo.js API for setting collision group and mask… That would be so awesome … Thansk again for all your help :slight_smile:

Mackey… have you found ANY AmmoJS demos/examples that use these parameters? (both on rigids and softs).

It’s likely that OIMO belongsTo (a grouping thing) and collidesWith (a masking-by-group thing) are parallels to those two Ammo params you speak-of.

In Oimo, which is just like Ammo only spelt different (not)… I needed to add belongsTo and collidesWith to a custom Oimo impostor and custom Oimo plugin.

Control-F search thru that PG… see how often those terms occur within those custom impostor and plugin classes. Get a “feel” for what it will take. (Yes, I realize that you are only looking for native calls and not necessarily BJS plugin/impostor support).

We need native-call examples, and it’s likely Trevor has not ever seen them either… so pressing him with capitalized “PLEASE”… likely won’t help.

I really doubt that Trevor has any more access to Ammo demos than you do. And, you might need to go to Bullet demos just to find anyone USING those parameters AT ALL. But, drop a line to the author(s) of AmmoJS… and just ask if demos with those two params being used… exist.

“PLEASE”… get some urls, show us code, and then, at minimum, hunt’n’peck Wingnut will start hacking on AmmoJS paddlewheel demo, seeing if I can get an under-the-plugin, under-the-impostor-wrapper… native-call to work.

What is taking so long? C’mon! :smiley:

Possible Assistance - from pyBullet example line 9. setCollisionFilterGroupMask()

It uses a .urdf file? Universal Robotic Description Format. hmm. Program a ‘robot’… how to “apply” the collision formula(s)? hmm. Object-by-object… custom colliding-formula-values… injection? (via xml files) Nice. Build-it-yourself impostor-shape/behaviors!

Yo @Wingnut … Man i cant find way to set the Collision Group and Mask using the Ammo.js API.

Maybe they just DID NOT EXPOSE the collision GROUP and MASK options to the BODY object along with all the other stuff like body.setCollisionFlags

Bummer… That would have been a kool option to EASE UP things on your OVERALL physics performance. Even Unity DOES NOT have a GUI to assign collision groups and masks… So from a Unity Exporter point of view, I got pretty much the entire Physics Component System exporting as metadata (MeshCollider, CapsuleCollider, SphereCollider, BoxCollider with special support for TerrainCollider that gets used by the Terrain Builder Exporter )

Note: WheelCollider is a special Unity Physics Component design for runtime support to handle wheel physics. It doe NOT really create a COVERAGE COLLIDER for a wheel. Its better to setup a Cylinder game object that is rotated and scaled to cover the wheel and use a ‘Mesh Collider’ component. If you need separate WHEEL physics.

But all and all… I got physics going much better and more complete (including compound collision setup all from the toolkit editor)… Working great so far :slight_smile:

Oh, sorry for the slow response, Mackey. From what you said in another thread, I thought you got it figged. Maybe you HAVE, by now.

That Bullet python code that I showed you last post… DOES hint-at exposure, right?

That is a demo… but it IS Bullet and not AmmoJS. Still… one would think that it would work.

Did you talk with AmmoJS author(s) and ask for JS demo that shows collisionFilterGroup and collisionFilterMask usage? I bet they have one, somewhere. Make them cough it up… we could ALL use it’s knowledge.

Do you think you could sort-of ADAPT the Bullet calls in that python code… to be JS calls to Ammo?

You have tried that a bunch, already?

I didnt see a body.setCollisionFilterGroupMask or body.setCollisionFilterPair

there are not exposed to the ‘body’ javascript object :frowning:

I don’t think ‘p’ is a ‘body’ object. import pybullet as p

‘p’ is the physics engine, I think. Not sure.

Let me know when you have talked to the author about a demo and published API. Until we see an AmmoJS API, we’re just speculating and feeling around in the dark, imho.

Ok, just a little more feeling around… Search · addCollisionObject · GitHub

‘group’ and ‘mask’ sure happen often in the params of addCollisionObject().


At minimum, addCollisionObject() is a new search term for us. :slight_smile: