[SOLVED] How can I change rigidbody type runtime?

I have many components, before I select component it must be static.
When I move it and then release it must be kinematic. When I release component I set linearVelocity vector to down.
When component striking with board I want to make it static back.

So, may I change rigidbody type of entity in runtime?

Yes, you can. To do this in script, you need to set the type property on a rigid body component:

http://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#type

Looks like the link to the enum is broken in the docs. You can set this property to a string:

  • ‘static’
  • ‘dynamic’
  • ‘kinematic’

I do this in the game Accelerally where I change a block from static to dynamic to make it fall on a trigger event:

https://playcanvas.com/editor/code/3489/collapsibleblock.js

1 Like

Thank you, looking for examples but not found, thank you very much.

1 Like

The enums are pc.BODYTYPE_* (not pc.RIGIDBODY_TYPE_*) … just in case anyone wonders.