返回介绍

Rigidbody 刚体

发布于 2019-12-18 15:38:28 字数 12413 浏览 1076 评论 0 收藏 0

class in UnityEngine / Inherits from: Component

Description 描述

Control of an object's position through physics simulation.

通过物理模拟控制一个物体的位置。

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组件到一个对象,这就置于了Unity的物理引擎下使其运动。即使没有添加任何代码,刚体对象也将在重力的影响下下落,如果带有碰撞器的对象与之碰撞,并将做出反应。

The Rigidbody also has a scripting API that lets you apply forces to the object and control it in a physically realistic way. For example, a car's behaviour can be specified in terms of the forces applied by the wheels. Given this information, the physics engine can handle most other aspects of the car's motion, so it will accelerate realistically and respond correctly to collisions.

从脚本添加力到刚体对象上,以真实的物理方法来控制它。例如,轿车的行为可以给轮胎施加力,物理引擎处理运动的其他方面,因此,会有更真实的加速度和正确的碰撞反应。

In a script, the FixedUpdate function is recommended as the place to apply forces and change Rigidbody settings (as opposed to Update, which is used for most other frame update tasks). The reason for this is that physics updates are carried out in measured time steps that don't coincide with the frame update. FixedUpdate is called immediately before each physics update and so any changes made there will be processed directly.

在脚本,FixedUpdate函数中被推荐放置应用力以及修改刚体设置(相对于Update,应用其他大部分更新任务)。物理更新的时间间隔与update是不一致的,在每个物理更新之前,FixedUpdate被立即调用,所以所作的任何更改会直接处理。

A common problem when starting out with Rigidbodies is that the game physics appears to run in “slow motion”. This is actually due to the scale used for your models. The default gravity settings assume that one world unit corresponds to one metre of distance. With non-physical games, it doesn't make much difference if your models are all 100 units long but when using physics, they will be treated as very large objects. If a large scale is used for objects that are supposed to be small, they will appear to fall very slowly - the physics engine thinks they are very large objects falling over very large distances. With this in mind, be sure to keep your objects more or less at their scale in real life (so a car should be about 4 units = 4 metres, for example).

当刚体运行开始常见的问题是,游戏物理引擎看上去运行像“慢镜头”。这实际上由于你模型的大小,默认重力设置假定为每世界单位1米距离。对非物理游戏,你的模型缩放100单位也没有多大差别,但当使用物理引擎,它们将被视为非常大的对象。如果应该是小对象使用较大的缩放,它们将出现下落很慢,物理引擎认为它是非常大的对象,下落较大的距离。考虑到这一点,请确保你的对象接近真实生活的大小(例如,轿车应该是大约4单位=4米)。

Variables 变量

angularDragThe angular drag of the object.
刚体的角阻力。
angularVelocityThe angular velocity vector of the rigidbody.
刚体的角速度向量。
centerOfMassThe center of mass relative to the transform's origin.
相对于变换原点的质心。
collisionDetectionModeThe Rigidbody's collision detection mode.
刚体的碰撞检测模式。
constraintsControls which degrees of freedom are allowed for the simulation of this Rigidbody.
控制该刚体模拟允许的自由度。
detectCollisionsShould collision detection be enabled? (By default always enabled).
碰撞检测应否启用?(默认总是启用的)
dragThe drag of the object.
刚体的阻力。
freezeRotationControls whether physics will change the rotation of the object.
控制物理是否改变物体的旋转。
inertiaTensorThe diagonal inertia tensor of mass relative to the center of mass.
相对于重心的质量的惯性张量对角线。
inertiaTensorRotationThe rotation of the inertia tensor.
惯性张量的旋转。
interpolationInterpolation allows you to smooth out the effect of running physics at a fixed frame rate.
插值允许你以固定的帧率平滑物理运行效果。
isKinematicControls whether physics affects the rigidbody.
控制物理是否够影响这个刚体。
massThe mass of the rigidbody.
刚体的质量。
maxAngularVelocityThe maximimum angular velocity of the rigidbody. (Default 7) range { 0, infinity }.
刚体的最大角速度,(默认7)范围{0, 无穷大}
maxDepenetrationVelocityMaximum velocity of a rigidbody when moving out of penetrating state.
当非穿透状态时,刚体的最大速度。
positionThe position of the rigidbody.
该刚体的位置。
rotationThe rotation of the rigdibody.
刚体的旋转角度。
sleepThresholdThe mass-normalized energy threshold, below which objects start going to sleep.
哪个对象开始进入休眠状态,质量归一化的能量阈值。
solverIterationCountAllows you to override the solver iteration count per rigidbody.
允许你覆盖每个刚体的求解迭代次数。
useConeFrictionForce cone friction to be used for this rigidbody.
用于该刚体的锥形摩擦力。
useGravityControls whether gravity affects this rigidbody.
控制重力是否影响整个刚体。
velocityThe velocity vector of the rigidbody.
刚体的速度向量。
worldCenterOfMassThe center of mass of the rigidbody in world space (Read Only).
在世界坐标空间的刚体的质量中心。(只读)

Public Functions 共有变量

AddExplosionForceApplies a force to a rigidbody that simulates explosion effects.
应用一个力到刚体来模拟爆炸效果。
AddForceAdds a force to the rigidbody.
添加到刚体的力。
AddForceAtPositionApplies force at position. As a result this will apply a torque and force on the object.
在position位置应用force力。作为结果这个将在这个物体上应用一个扭矩和力。
AddRelativeForceAdds a force to the rigidbody relative to its coordinate system.
添加力到刚体。相对于它的系统坐标。
AddRelativeTorqueAdds a torque to the rigidbody relative to its coordinate system.
相对于它的局部坐标系统添加扭矩到刚体。
AddTorqueAdds a torque to the rigidbody.
添加扭矩到刚体。
ClosestPointOnBoundsThe closest point to the bounding box of the attached colliders.
指定位置到该刚体附加的碰撞器的最近点。
GetPointVelocityThe velocity of the rigidbody at the point worldPoint in global space.
刚体在世界坐标空间,worldPoint点的速度。
GetRelativePointVelocityThe velocity relative to the rigidbody at the point relativePoint.
相对于刚体在relativePoint点的速度。
IsSleepingIs the rigidbody sleeping?
刚体在休眠么?
MovePositionMoves the rigidbody to position.
移动刚体到新位置。
MoveRotationRotates the rigidbody to rotation.
旋转刚体到新角度。
ResetCenterOfMassReset the center of mass of the rigidbody.
重置刚体的质心。
ResetInertiaTensorReset the inertia tensor value and rotation.
重置惯性张量值和旋转。
SetDensitySets the mass based on the attached colliders assuming a constant density.
设置基于附加的碰撞器假设一个固定的密度质量。
SleepForces a rigidbody to sleep at least one frame.
强制刚体休眠。
SweepTestTests if a rigidbody would collide with anything, if it was moved through the scene.
如果一个刚体碰到任何东西触发测试。
SweepTestAllLike Rigidbody.SweepTest, but returns all hits.
就像Rigidbody.SweepTest,当返回的是所有碰撞信息。
WakeUpForces a rigidbody to wake up.
强制一个刚体唤醒。

Messages 消息

OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
当collider/rigidbody接触到另一个rigidbody/collider时,OnCollisionEnter被调用。
OnCollisionExitOnCollisionEnter is called when this collider/rigidbody has stopped touching another rigidbody/collider.
当collider/rigidbody停止接触到另一个rigidbody/collider时,OnCollisionExit被调用。
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
当collider/rigidbody一旦接触另一个rigidbody/collider时,OnCollisionStay每帧被调用。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文