Limiting a Physics6DoFConstraint Motor (Havok)

Hi,

I’m new to this forum but have been working with BabylonJS for some time, apologies in advance if this is my mistake and not an actual issue.

I’m building a simple pinball game using BabylonJS and Havok. My understanding is that hinge constrains cannot be limited like v1 HingeJoints could, and the only way to limit a constraint is to use Physics6DoFConstraint. That’s fine.

For the flipper in pinball, I’ve implemented a Physics6DoFConstraint with limits and have motorized it, but it will always get stuck and I can’t figure out why.

I’ve recreated the “unlimited” version in a playground (press the Z key to apply force). Removing the comment from lines 70-75 applies the limit, and now the flipper will be stuck despite any counter force applied to it when pressing Z.

Am I missing something here?

1 Like

Welcome to the forum! :smiley:

Hmmm I’m not sure if the max force is being applied as expected here, let me tag @eoin to have a look when possible

So, setAxisMotorMaxForce() just configures how much force the motor is allowed to apply – i.e. how hard the motor can push the object. It doesn’t affect where the motor is trying to get to. You’ll want to keep the max force constant and experiment with changing the setAxisMotorTarget(), which will cause the constraint to push to a different position.

Also, just a thought, but maybe worth considering; constraints can be a little soft (especially if a fast, heavy object collides with the constrained object) - if you want precise control over where your flipper is, you might consider making the flippers kinematic and changing their velocity or driving them to a target, so they’ll always go to exactly the pose that you expect. The plugin has a helper function for driving to a target (HP_Body_SetTargetQTransform) which you can extract from the plugin (but would be good to expose this to the PhysicsBody interface @carolhmj :)) or you can set a velocity on the body.

2 Likes

Thank you both, this has been very helpful.

I had a similar issue with setAxisMotorTarget, which takes a target velocity (rather than a position/rotation). Using HP_Body_SetTargetQTransform might be a bit beyond me at the moment as I’m following the documentation, but I’ve found a workaround by using setAngularVelocity. I have updated the playground example in case others find it useful:

Forgot to update here, but setTargetTransform was added on the framework: https://github.com/BabylonJS/Babylon.js/blob/6a8a093dd73b8d59cf3382b453f7ad72cd6416ed/packages/dev/core/src/Physics/v2/physicsBody.ts#L585
Now I have to update the docs

Fantastic, thank you

Documentation is being updated also add mention of setTargetTransform on rigid bodies docs by carolhmj · Pull Request #1026 · BabylonJS/Documentation (github.com)

1 Like