Collisions between physics object and non-physics object (or how to ignore gravity for a physics obj)

I want to have suspended discs in the air (or anywhere) that allow me to detect collisions with objects that are part of the normal physics system.

I’ve adapted the bowling example. Press w in this playground and you can see the ball goes straight through the disc and no physics/collisions events are triggered:

If I add a cylinder physics aggregate, the collision works, but then the disc doesn’t hang in the air anymore.

You would need the same functionality for e.g. hanging platforms in a platformer game.

I’ve tried:

  • Giving the disc physics aggregate 0 mass - it still falls but now doesn’t even land on the bowling lane
  • Using checkCollisions = true from the moveWithCollisions example, but I’ve seen elsewhere that the two different collision systems don’t work together well

Is there any way to either:
a) freeze an object’s physics so gravity doesn’t affect it, but you can still get collision events

or

b) detect collisions between physics imposters and non-physics objects/regions, like the disc I want to use

Any other way to potentially achieve what I want would also be very helpful! Thanks.

I’ve seen a few others ask this before with no progress:

Many thanks,
Paul

Hello and welcome abroad!
This is a great use for collision triggers: Collisions | Babylon.js Documentation (babylonjs.com) :slight_smile:
Edit: Here’s your example using a trigger: Disc/circle collision with physics imposter | Babylon.js Playground (babylonjs.com)

1 Like

Thanks! I’m not sure collision triggers can fix it because the problem is that I want to use Havok physics for collisions, but allow one of the objects to float. The hard part is preventing the floating object from obeying ordinary physics, while still enabling collision detection. Can triggers help me with that part of the problem?

After a few hours of banging my head against the wall, I actually have a working example of this now here: Babylon.js Playground

I create an invisible dummy object with mass zero as the reference point for my floating object, then I attach the disc (that I want to collide properly) with a 6DoF constraint to the floating invisible object, with a constraint that says they must be zero distance apart.

I can then place the invisible dummy anywhere and the disc object moves to that location without gravity being able to affect it. But it still collides correctly because the disc object itself has a physics imposter with mass.

Hope this is helpful for someone else!

If anyone knows of a simpler way to achieve it, I’d love to know.

That’s precisely what triggers do, they’re Havok bodies which are not affected by physics and just report collision events

3 Likes

Amazing, thanks for the edit with your playground example!

Sorry for misunderstanding. The triggers reference by itself still left me a bit confused because I didn’t grasp that you were referring to the Triggers example lower down that page (bad brain day, obviously). Now I see that the Triggers playground example shows exactly how to set up collision events with static objects.

So a key bit in your edit for me was:
var circleBody = new BABYLON.PhysicsBody(circle, BABYLON.PhysicsMotionType.STATIC, false, scene);

This totally solves this for me, and is a million times simpler than my hacky constraints solution. Thanks so much for your help!

3 Likes