Skip to main content

<pc-rigid-body>

The <pc-rigid-body> tag makes an entity a rigid body in the physics simulation: a static one that never moves, a dynamic one that gravity and collisions move, or a kinematic one that you move yourself.

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). A collision's bounce is the product of both bodies' restitution, so a body only bounces off another that has some too
rolling-frictionNumber"0"Rolling resistance coefficient
typeEnum"static"Physics body type: "static" | "kinematic" | "dynamic"

Example​

Dynamic bodies falling onto a static ground. A collision's bounce is the product of the two bodies' restitution, so the ground has restitution="1" and the sphere, with "0.9", keeps most of its speed. Try giving the boxes some bounce too, or setting the ground's restitution to 0 to stop every bounce:

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 normal-offset-bias="0.05" shadow-bias="0.2"></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" restitution="1"></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.

The component property is the engine RigidBodyComponent the element adds — null until the element is ready — and everything the attributes do not expose is available on it.

See Also​

Examples: Basic Physics, Physics Cluster, Ragdoll and Vehicle Physics.