Skip to Content
🎉 @playcanvas/react 0.3.0! Now with React 19 support. Read more →
️💡

Enable physics by installing npm i sync-ammo and enabling physics on the Application using<Application usePhysics/>.

The Collision component attaches a PlayCanvas Collision Component to an Entity.

It allows an Entity to participate in collision detection with other entities that have collision components. This is useful for physics simulations, trigger zones, and other gameplay mechanics that require detecting when objects intersect.

Learn more about Collision components in the PlayCanvas documentation. Also see the Rigidbody component for more information on how to use collision components with physics.

Usage

You attach a Collision component to an Entity in the same way you would attach a Render component. To work with physics, you should also attach a Rigidbody component to the same Entity, and probably a Render component too.

collision.jsx
import { Collision, Rigidbody } from '@playcanvas/react/components' const CollisionExample = () => { return <Entity> <Collision type="box" /> <RigidBody type="dynamic" mass={12} /> <Render type="box" /> </Entity> }

Props

The following props are based on the Collision API from PlayCanvas version 2.7.3. This documentation is automatically generated from the TypeScript types of the installed PlayCanvas package.

NameTypeDefault
type"box" | "capsule" | "compound" | "cone" | "cylinder" | "mesh" | "sphere"
halfExtentsVec3

Sets the half-extents of the box-shaped collision volume in the x, y and z axes. Defaults to [0.5, 0.5, 0.5]. Gets the half-extents of the box-shaped collision volume in the x, y and z axes.

linearOffsetVec3

Sets the positional offset of the collision shape from the Entity position along the local axes. Defaults to [0, 0, 0]. Gets the positional offset of the collision shape from the Entity position along the local axes.

angularOffsetQuat

Sets the rotational offset of the collision shape from the Entity rotation in local space. Defaults to identity. Gets the rotational offset of the collision shape from the Entity rotation in local space.

radiusnumber

Sets the radius of the sphere, capsule, cylinder or cone-shaped collision volumes. Defaults to 0.5. Gets the radius of the sphere, capsule, cylinder or cone-shaped collision volumes.

axisnumber

Sets the local space axis with which the capsule, cylinder or cone-shaped collision volume’s length is aligned. 0 for X, 1 for Y and 2 for Z. Defaults to 1 (Y-axis). Gets the local space axis with which the capsule, cylinder or cone-shaped collision volume’s length is aligned.

heightnumber

Sets the total height of the capsule, cylinder or cone-shaped collision volume from tip to tip. Defaults to 2. Gets the total height of the capsule, cylinder or cone-shaped collision volume from tip to tip.

assetnumber | Asset | null

Sets the asset or asset id for the model of the mesh collision volume. Defaults to null. Gets the asset or asset id for the model of the mesh collision volume.

renderAssetnumber | Asset | null

Sets the render asset or asset id of the mesh collision volume. Defaults to null. If not set then the asset property will be checked instead. Gets the render asset id of the mesh collision volume.

convexHullboolean

Sets whether the collision mesh should be treated as a convex hull. When false, the mesh can only be used with a static body. When true, the mesh can be used with a static, dynamic or kinematic body. Defaults to false. Gets whether the collision mesh should be treated as a convex hull.

shapeany
modelModel | null

Sets the model that is added to the scene graph for the mesh collision volume. Gets the model that is added to the scene graph for the mesh collision volume.

renderany
checkVertexDuplicatesboolean

Sets whether checking for duplicate vertices should be enabled when creating collision meshes. Gets whether checking for duplicate vertices should be enabled when creating collision meshes.

systemComponentSystem

The ComponentSystem used to create this Component.

entityEntity

The Entity that this Component is attached to.

enabledboolean

Sets the enabled state of the component. Gets the enabled state of the component.

Last updated on