メインコンテンツまでスキップ

<Rigidbody/>

<Rigidbody/> コンポーネントは <Entity/> に質量、速度、摩擦などの物理プロパティを付与し、グローバル物理シミュレーションとの対話を可能にします。<Rigidbody/> を持つ <Entity/> は重力、力、トルク、その他の物理挙動に反応します。

PlayCanvas の物理システムの仕組みについては 物理ドキュメント を、React 固有の詳細については React の物理 ガイドを参照してください。

はじめに

ヒント

PlayCanvas で物理を使用するには ammo.js と <Application usePhysics/> の有効化が必要です。アプリ内で npm i sync-ammo を実行してください。

<Rigidbody/> コンポーネントを使用するには、sync-ammo 依存関係をインストールし、ルートの <Application/> コンポーネントに <Application usePhysics/> Prop を設定する必要があります。これにより物理システムが有効になり、Entity が物理シミュレーションと対話できるようになります。

詳細は React の物理 ガイドを参照してください。

使い方

<Entity/><Rigidbody/> コンポーネントを追加します。剛体の形状を定義するために <Collision/> コンポーネントも Entity に追加する必要があります。

<Application usePhysics>
<Entity>
<Rigidbody type="box" />
</Entity>
</Application>

PlayCanvas ドキュメントの RigidBody Component で詳細を確認できます。

プロパティ

NameTypeDefault
type?
"dynamic" | "kinematic" | "static"
Sets the rigid body type determines how the body is simulated.
"static"
angularDamping?
number
Sets the rate at which a body loses angular velocity over time. Gets the rate at which a body loses angular velocity over time.
-
angularFactor?
[number, number, number]
Sets the scaling factor for angular movement of the body in each axis. Only valid for rigid bodies of type BODYTYPE_DYNAMIC. Defaults to 1 in all axes (body can freely rotate). Gets the scaling factor for angular movement of the body in each axis.
-
angularVelocity?
[number, number, number]
Sets the rotational speed of the body around each world axis. Gets the rotational speed of the body around each world axis.
-
body?
any
-
friction?
number
Sets the friction value used when contacts occur between two bodies. A higher value indicates more friction. Should be set in the range 0 to 1. Defaults to 0.5. Gets the friction value used when contacts occur between two bodies.
-
group?
number
Sets the collision group this body belongs to. Combine the group and the mask to prevent bodies colliding with each other. Defaults to 1. Gets the collision group this body belongs to.
-
linearDamping?
number
Sets the rate at which a body loses linear velocity over time. Defaults to 0. Gets the rate at which a body loses linear velocity over time.
-
linearFactor?
[number, number, number]
Sets the scaling factor for linear movement of the body in each axis. Only valid for rigid bodies of type BODYTYPE_DYNAMIC. Defaults to 1 in all axes (body can freely move). Gets the scaling factor for linear movement of the body in each axis.
-
linearVelocity?
[number, number, number]
Sets the speed of the body in a given direction. Gets the speed of the body in a given direction.
-
mask?
number
Sets the collision mask sets which groups this body collides with. It is a bit field of 16 bits, the first 8 bits are reserved for engine use. Defaults to 65535. Gets the collision mask sets which groups this body collides with.
-
mass?
number
Sets the mass of the body. This is only relevant for BODYTYPE_DYNAMIC bodies, other types have infinite mass. Defaults to 1. Gets the mass of the body.
-
restitution?
number
Sets the value that controls the amount of energy lost when two rigid bodies collide. The calculation multiplies the restitution values for both colliding bodies. A multiplied value of 0 means that all energy is lost in the collision while a value of 1 means that no energy is lost. Should be set in the range 0 to 1. Defaults to 0. Gets the value that controls the amount of energy lost when two rigid bodies collide.
-
rollingFriction?
number
Sets the torsional friction orthogonal to the contact point. Defaults to 0. Gets the torsional friction orthogonal to the contact point.
-
system?
ComponentSystem
The ComponentSystem used to create this Component.
-
entity?
Entity
The Entity that this Component is attached to.
-
enabled?
boolean
Sets the enabled state of the component. Gets the enabled state of the component.
-