Skip to content

Rigidbody

继承自 Component

RigidBody类主要用于游戏对象的物理模拟,为游戏对象添加物理效果。

在运行过程中,可以使用以下方式来获取RigidBody组件对象:

typescript
let obj = new GameObject();
let rigid = obj.AddComponent<Rigidbody>(Rigidbody);

成员变量

Rigidbody.isSleeping : boolean
(只读)刚体是否处于休眠状态。
Rigidbody.solverIterations : number
物理引擎在求解位置时的迭代次数。
Rigidbody.useGravity : boolean
刚体是否受重力影响。
Rigidbody.isKinematic : boolean
刚体是否启用刚体的运动模拟。
Rigidbody.freezeRotation : boolean
刚体是否可在任何方向上旋转。
Rigidbody.detectCollisions : boolean
是否启用碰撞检测。
Rigidbody.interpolation : RigidbodyInterpolation
如何进行物体的插值运算。
Rigidbody.centerOfMass : Vector3
刚体的质心位置。
Rigidbody.mass : number
刚体的质量。
Rigidbody.solverVelocityIterations : number
物理引擎计算刚体速度时的迭代次数。
Rigidbody.drag : number
刚体在运动中受到的空气阻力。
Rigidbody.angularDrag : number
对象的角阻力。
Rigidbody.sleepThreshold : number
刚体进入休眠状态的速度阈值。
Rigidbody.maxAngularVelocity : number
刚体的最大角速度。
Rigidbody.maxLinearVelocity : number
刚体的最大线速度。
Rigidbody.worldCenterOfMass : Vector3
(只读)世界空间中刚体的质心位置。
Rigidbody.maxDepenetrationVelocity : number
刚体的最大的反穿透速度。
Rigidbody.position : Vector3
刚体的位置。
Rigidbody.velocity : Vector3
刚体的速度矢量。
Rigidbody.angularVelocity : Vector3
刚体的角速度矢量。
Rigidbody.inertiaTensor : Vector3
该物体的惯性张量
Rigidbody.rotation : Quaternion
刚体的旋转。
Rigidbody.inertiaTensorRotation : Quaternion
该物体惯性张量的旋转。
Rigidbody.raints : RigidbodyConstraints
控制该刚体的模拟自由度。
Rigidbody.collisionDetectionMode : CollisionDetectionMode
刚体的碰撞检测模式。
Rigidbody.density : void
(只写)根据附加的碰撞器设置质量。

成员方法

Rigidbody.AddExplosionForce ( explosionForce : number , explosionPosition : Vector3 , explosionRadius : number , upwardsModifier : number , mode : ForceMode ) : void
对模拟爆炸效果的刚体施加力。
Rigidbody.AddRelativeTorque ( torque : Vector3 , mode : ForceMode ) : void
给刚体添加一个相对于其坐标系的扭矩。
Rigidbody.ClosestPointOnBounds ( position : Vector3 ) : ClosestPoint
返回到指定点最近的刚体包围盒上的点的平方距离与坐标。
Rigidbody.GetPointVelocity ( value : Vector3 ) : Vector3
刚体在世界坐标中特定点的速度向量。
Rigidbody.AddForce ( force : Vector3 , mode : ForceMode ) : void
向刚体添加力。
Rigidbody.MovePosition ( value : Vector3 ) : void
移动刚体位置。
Rigidbody.AddForceAtPosition ( force : Vector3 , position : Vector3 , mode : ForceMode ) : void
在指定位置上施加力。
Rigidbody.AddRelativeForce ( force : Vector3 , mode : ForceMode ) : void
给刚体添加一个本地坐标系的力。
Rigidbody.AddTorque ( torque : Vector3 , mode : ForceMode ) : void
向刚体添加扭矩。
Rigidbody.GetRelativePointVelocity ( value : Vector3 ) : Vector3
刚体上给定点的相对速度。
Rigidbody.MoveRotation ( value : Quaternion ) : void
旋转刚体的角度。
Rigidbody.ResetCenterOfMass ( ) : void
重置刚体的质心。
Rigidbody.ResetInertiaTensor ( ) : void
重置惯性张量值和旋转。
Rigidbody.Sleep ( ) : void
刚体休眠。
Rigidbody.WakeUp ( ) : void
唤醒刚体。
Rigidbody.SweepTest ( direction : Vector3 , maxDistance : number? ) : RaycastHit|undefined
测试如果刚体在场景中移动时,是否会与任何对象发生碰撞。