How to disable a constraint when an object is not on the ground?

I want to disable or remove a constraint from an object only in specific frames — for example, when the object is not touching the ground anymore.

Is there a recommended way to check this condition during the animation or physics update? And how can I properly disable the constraint at that moment?

Any advice or examples would be very appreciated. Thanks!

You may have a look how it is done here - Babylon.js/packages/dev/core/src/Physics/v2/characterController.ts at 1e934b40d62f8965c418f0637dc7fa302016fc2b · BabylonJS/Babylon.js · GitHub

1 Like

Thanks for the reply, but I think I didn’t explain my use case clearly.

I’m not using CharacterController. Instead, I’m using a physics constraint (Physics6DoFConstraint) to control a motorized object (e.g., a wheel).
What I want to do is dynamically remove or disable this constraint under certain conditions, such as:

  • When the motor speed gets too high
  • Or when the object is no longer in contact with the ground (it’s in the air)

Is there a recommended way to Properly remove or disable the constraint during the physics update?

Any tips or example code would be super helpful!

I am not suggesting using CC in your case, but there are code snippets which may be useful to detect needed states (ON_GROUND, ON_AIR etc) in your case.
Here is PG example - https://playground.babylonjs.com/#WO0H1U#13

Thanks! That playground was helpful.

Just to clarify:
If the state becomes "IN_AIR", how can I disable or remove the constraint?
I see there’s an addConstraint method like:

fixedMass.body.addConstraint(plane.body, joint);

But I couldn’t find a removeConstraint method.
Is there a recommended way to disable or remove a constraint dynamically?

The simplest is joint.setEnabled(false) , if it is applicable in your case.

Thank you.

1 Like

setEnabled is not a function but i think joint.isEnabled = false worked.

1 Like

Yes, I got it mixed up with the syntax for meshes :slight_smile:

1 Like