Skip to main content

<pc-rigid-body>

The <pc-rigid-body> tag is used to define a rigidbody component.

Usage

Attributes

AttributeTypeDefaultDescription
angular-dampingNumber"0"Angular velocity damping factor
angular-factorVector3"1 1 1"Angular movement constraints as "X Y Z" values
enabledBoolean"true"Enabled state of the component
frictionNumber"0.5"Surface friction coefficient
linear-dampingNumber"0"Linear velocity damping factor
linear-factorVector3"1 1 1"Linear movement constraints as "X Y Z" values
massNumber"1"Mass of the rigidbody in kilograms
restitutionNumber"0"Bounce/elasticity coefficient (0-1)
rolling-frictionNumber"0"Rolling resistance coefficient
typeEnum"static"Physics body type: "static" | "kinematic" | "dynamic"

Example

Dynamic bodies falling onto a static ground. The sphere has restitution="0.9", so it bounces — try giving the boxes some bounce too, or changing their mass:

Live Example
<pc-app>
<pc-wasm name="Ammo" glue="https://developer.playcanvas.com/assets/modules/ammo/ammo.wasm.js" wasm="https://developer.playcanvas.com/assets/modules/ammo/ammo.wasm.wasm" fallback="https://developer.playcanvas.com/assets/modules/ammo/ammo.js"></pc-wasm>
<pc-scene>
<pc-entity name="camera" position="0 2 8">
<pc-camera clear-color="#1d1f2b"></pc-camera>
</pc-entity>
<pc-entity name="light" rotation="45 30 0">
<pc-light cast-shadows></pc-light>
</pc-entity>
<pc-entity name="box-1" position="-1.5 4 0" rotation="30 10 40">
<pc-render type="box"></pc-render>
<pc-collision></pc-collision>
<pc-rigid-body type="dynamic"></pc-rigid-body>
</pc-entity>
<pc-entity name="box-2" position="0 6 0" rotation="10 40 20">
<pc-render type="box"></pc-render>
<pc-collision></pc-collision>
<pc-rigid-body type="dynamic"></pc-rigid-body>
</pc-entity>
<pc-entity name="ball" position="1.5 5 0">
<pc-render type="sphere"></pc-render>
<pc-collision type="sphere"></pc-collision>
<pc-rigid-body type="dynamic" restitution="0.9"></pc-rigid-body>
</pc-entity>
<pc-entity name="ground" position="0 -0.5 0" scale="12 1 12">
<pc-render type="box"></pc-render>
<pc-collision half-extents="6 0.5 6"></pc-collision>
<pc-rigid-body type="static"></pc-rigid-body>
</pc-entity>
</pc-scene>
</pc-app>

JavaScript Interface

You can programmatically create and manipulate <pc-rigid-body> elements using the RigidBodyComponentElement API.