Version: 2021.3
言語: 日本語

Rigidbody

class in UnityEngine

/

継承:Component

マニュアルに切り替える

説明

物理演算によりオブジェクトの位置を制御します。

Adding a Rigidbody component to an object will put its motion under the control of Unity's physics engine. Even without adding any code, a Rigidbody object will be pulled downward by gravity and will react to collisions with incoming objects if the right Collider component is also present.

また、Rigidbody はオブジェクトに力を適用し、物理的に現実的な方法でそれをコントロールするためのスクリプト API も有しています。例えば、ある自動車の挙動は車輪によって加えられる力という面から指定することができます。この情報に基づけば、物理エンジンは車の挙動のその他ほとんどの側面を扱うことができるので、現実的に加速したり、衝突に対して正確に応答します。

スクリプトでは、FixedUpdate 関数は力を適用したり、Rigidbody の設定を変更する場所とすることが推奨されます(対照に Update は、その他ほとんどのフレーム更新作業で使用されます)。理由は、物理挙動の更新が時間進行単位で行われており、フレーム更新は関係ないからです。FixedUpdate は物理挙動更新の直前に呼び出されるため、その中でなされたどのような変更も直接反映されます。

Rigidbody で作業を始める際の一般的な問題には、ゲームの物理挙動が「スローモーション」で実行されているように見えるというものがあります。これは実際にあなたのモデルに使用されているスケールに起因しているものです。デフォルトの重力設定は、1 ワールドユニットが距離の 1 メートルに対応することを前提としています。非物理的なゲームでは、あなたのモデルがすべて 100 ユニットの長さであっても大した差はありませんが、物理挙動を用いればそれらはとても大きなオブジェクトとして扱われます。もし小さいと思われるようなオブジェクトに大きなスケールを使用すれば、それらはとてもゆっくりと落下しているように見えます。なぜなら、物理エンジンはそれらをとても長い距離を落下しているとても大きなオブジェクトと見なすからです。このことを念頭に置き、オブジェクトは現実の生活のスケールよりも大きく、または小さくするようにしましょう(したがって、例えば車は 4 ユニット = 4 メートルほどにしておくべきです)。

変数

angularDragオブジェクトの Angular drag (回転抗力)
angularVelocityThe angular velocity vector of the rigidbody measured in radians per second.
centerOfMassTransform の原点に対する質量の中心
collisionDetectionModeRigidbody の衝突検出モード
constraintsRigidbody のシミュレーションで自由に操作できる軸をコントロールします
detectCollisions衝突検出を有効にするかどうか(デフォルトでは常に有効)
dragオブジェクトの Drag (抗力)
freezeRotation物理演算による回転の影響を受けるかどうか
inertiaTensorThe inertia tensor of this body, defined as a diagonal matrix in a reference frame positioned at this body's center of mass and rotated by Rigidbody.inertiaTensorRotation.
inertiaTensorRotation慣性テンソルの回転角度
interpolationinterpolation を使用することで、固定フレームレートで物理処理実行のエフェクトをなめらかにできます。
isKinematic物理演算の影響を受けるかどうか
massRigidbody の質量
maxAngularVelocityThe maximimum angular velocity of the rigidbody measured in radians per second. (Default 7) range { 0, infinity }.
maxDepenetrationVelocity貫通状態から出るときのリジッドボディの最大速度
positionRigidbody の位置
rotationThe rotation of the Rigidbody.
sleepThresholdオブジェクトがスリープ状態に入る、質量で正規化された運動エネルギーのしきい値。
solverIterationssolverIterations はリジッドボディのジョイントと衝突の接触がどれだけ正確に解決されるかに影響を与えます。Physics.defaultSolverVelocityIterations をオーバーライドします。正数でなければなりません。
solverVelocityIterationssolverVelocityIterations はリジッドボディのジョイントと衝突の接触がどれだけ正確に解決されるかに影響を与えます。Physics.defaultSolverVelocityIterations をオーバーライドします。正数でなければなりません。
useGravityRigidbody が重力の影響を受けるかどうか
velocityThe velocity vector of the rigidbody. It represents the rate of change of Rigidbody position.
worldCenterOfMassワールド座標による質量の中心値(読み取り専用)

Public 関数

AddExplosionForce爆発のエフェクトをシミュレートするために Rigidbody に力を適用させます。
AddForce Rigidbody に力を加えます
AddForceAtPosition特定の位置から力を適用します。結果、これはトルクを適用しオブジェクトに力を加えます
AddRelativeForceローカル座標に対して Rigidbody に相対的な力を加えます。
AddRelativeTorqueローカル座標に対して Rigidbody に相対的な力を加えます。
AddTorqueRigidbody にトルクを追加します
ClosestPointOnBoundsアタッチされたコライダーのバウンディングボックスにもっとも近い位置
GetPointVelocityワールド座標における、Rigidbody オブジェクトの速度を取得します
GetRelativePointVelocityローカル座標における、Rigidbody オブジェクトの相対的速度を取得します
IsSleepingスリープモードかどうか
MovePositionMoves the kinematic Rigidbody towards position.
MoveRotationRigidbody オブジェクトを指定する角度へ回転します
ResetCenterOfMassRigidbody の重心をリセットします。
ResetInertiaTensor慣性テンソル値と回転をリセットします。
SetDensity不変な密度と仮定してアタッチされたコライダーをもとに質量を設定します
Sleep最新の 1 フレームで Rigidbody を強制的にスリープモードにします
SweepTestTests if a rigidbody would collide with anything, if it was moved through the Scene.
SweepTestAll Rigidbody.SweepTest のようですが、これはヒットしたすべてを返します
WakeUp強制的にスリープモードを解除します

メッセージ

OnCollisionEnterこの collider/rigidbody は他の collider/rigidbody に触れたときに OnCollisionEnter は呼び出されます。
OnCollisionExitこの collider/rigidbody が他の collider/rigidbody と触れ合うのをやめたときに OnCollisionExit は呼び出されます。
OnCollisionStayOnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody.

継承メンバー

変数

gameObjectこのコンポーネントはゲームオブジェクトにアタッチされます。コンポーネントはいつもゲームオブジェクトにアタッチされています。
tagゲームオブジェクトのタグ
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameオブジェクト名

Public 関数

BroadcastMessageゲームオブジェクトまたは子オブジェクトにあるすべての MonoBehaviour を継承したクラスにある methodName 名のメソッドを呼び出します。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentReturns the component of type if the GameObject has one attached.
GetComponentInChildrenReturns the Component of type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the Component of type in the GameObject or any of its parents.
GetComponents GameObject から type のタイプのコンポーネントを「すべて」取得します。
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children using depth first search. Works recursively.
GetComponentsInParent GameObject や深さ優先探索を活用して、親子関係にある親オブジェクトから type のタイプのコンポーネントを「すべて」取得します。
SendMessageゲームオブジェクトにアタッチされているすべての MonoBehaviour にある methodName と名付けたメソッドを呼び出します
SendMessageUpwardsゲームオブジェクトと親(の親、さらに親 ... )にアタッチされているすべての MonoBehaviour にある methodName と名付けたメソッドを呼び出します
TryGetComponentGets the component of the specified type, if it exists.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static 関数

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeタイプ type から最初に見つけたアクティブのオブジェクトを返します
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiateoriginal のオブジェクトをクローンします

Operator

boolオブジェクトが存在するかどうか
operator !=二つのオブジェクトが異なるオブジェクトを参照しているか比較します
operator ==2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。