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.
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.