Skip to Content
🎉 @playcanvas/react 0.2.1 is released. Read more →

Collision

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.

import { Collision, Rigidbody } from '@playcanvas/react/components' <Entity> <Collision type="box" /> <RigidBody type="dynamic" mass={12} /> <Render type="box" /> </Entity> }

Props

type

The type of collision shape to attach to the Entity.

Type: "box" | "sphere" | "capsule" | "mesh" | "compound" | "cone" | "cylinder" Default: "box"

asset

The asset to use for the collision shape.

Type: Asset

Additional Props

Any additional props will be passed to the CollisionComponent class directly. See the documentation for more information.

Last updated on