<Collision/>
<Collision/> コンポーネントは、PlayCanvas の Collision Component を Entity にアタッチします。
Collision Component を持つ他の Entity とのコリジョン検出に参加できるようになります。物理シミュレーション、トリガーゾーン、オブジェクトの交差を検出する必要があるその他のゲームプレイメカニクスに便利です。
注記
sync-ammo をインストールし、<Application usePhysics/> で Application の物理を有効にしてください。
使い方
Collision コンポーネントは、Render コンポーネントと同じ方法で Entity にアタッチします。物理を使用するには、同じ Entity に Rigidbody コンポーネントもアタッチする必要があり、おそらく Render コンポーネントも必要です。
import { Application, Entity } from '@playcanvas/react'
import { Collision, Rigidbody, Render } from '@playcanvas/react/components'
export default function Scene() {
return (
<Application usePhysics>
<Entity>
<Collision type="box" />
<Rigidbody type="dynamic" mass={12} />
<Render type="box" />
</Entity>
</Application>
)
}
PlayCanvas ドキュメントの Collision Components で詳細を確認できます。物理での Collision コンポーネントの使用については Rigidbody コンポーネントも参照してください。
プロパティ
| Name | Type | Default |
|---|---|---|
type? | "box" | "capsule" | "compound" | "cone" | "cylinder" | "mesh" | "sphere"Sets the type of the collision volume. Can be:
- "box": A box-shaped collision volume.
- "capsule": A capsule-shaped collision volume.
- "compound": A compound shape. Any descendant entities with a collision component of type
box, capsule, cone, cylinder or sphere will be combined into a single, rigid shape.
- "cone": A cone-shaped collision volume.
- "cylinder": A cylinder-shaped collision volume.
- "mesh": A collision volume that uses a model asset as its shape.
- "sphere": A sphere-shaped collision volume.
Defaults to "box".
Gets the type of the collision volume. | - |
halfExtents? | [number, number, number]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. | - |
linearOffset? | [number, number, number]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. | - |
angularOffset? | [number, number, number, number]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. | - |
radius? | numberSets 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. | - |
axis? | numberSets 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. | - |
height? | numberSets 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. | - |
asset? | number | Asset | nullSets 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. | - |
renderAsset? | number | Asset | nullSets 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. | - |
convexHull? | booleanSets 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. | - |
shape? | any | - |
model? | Model | nullSets 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. | - |
render? | any | - |
checkVertexDuplicates? | booleanSets 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. | - |
system? | ComponentSystemThe ComponentSystem used to create this Component. | - |
entity? | EntityThe Entity that this Component is attached to. | - |
enabled? | booleanSets the enabled state of the component.
Gets the enabled state of the component. | - |