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.
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.
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: