How to achieve simple springbone in PlayCanvas?

Hi there,

How to achieve simple springbone in play canvas?
Similar to these two:

This is a common effect in many games and applications.

Anyone here? :smiling_face_with_tear:

Afraid its not possbile out of the box. You will have have to write the simulation yourself via bones in a model or try using physics constraints via Ammo https://playcanvas.com/project/618829/overview/physics-constraints

I think Ammo might have spring constraint exposed but not 100% and you will have to dig around a little in their repo

PlayCanvas has a “secret” joint component, which is based on Ammo’s btGeneric6DofSpringConstraint. I believe @will added it not long ago. It is not exposed via Editor, so you may only add it via code. However, I would not recommend it at the moment, since the engine doesn’t support it yet. The rigidbody component system needs some changes to prevent Ammo from crashing, if you would add it as a component like:

entity.addComponent('joint');

However, you could still reference the code, as an example of how you can create a joint yourself. If you lock the motion of all axes but one and add stiffness, it will become a spring. You would then be responsible for its lifecycle, though - you must make sure not to destroy a rigidbody if it is connected to a joint, or Ammo will crash. You must clear the joint first.

1 Like

Oh cool, I knew the components were in the engine privately but didn’t realise he exposed the spring component

1 Like

Yes, this is a generic constraint and quite powerful - you can create any type of joint from it, like a hinge, a motor, a spring, etc, depending on the configuration.