Unity—Rigidbody-Collider笔记

翻译转载自官方文档圣典等处:

ceeger link

Kinematic:

当刚体标记为运动学模式,他不会受到碰撞,力及任何物理影响,它表示你必须直接通过(Transform.position/.rotation)变换的方式来操纵该物体。

运动学模式的刚体会与其他物体进行物理交互,但自身不受物理系统的影响。例如,通过关节约束那些和运动学刚体连接起来的刚体,那些与之发生碰撞的刚体则会受到运动学刚体影响,受到物理系统控制影响。

Colliders:碰撞器

Colliders define the physical boundaries of a Rigidbody 碰撞器定义刚体的物理边界,它和刚体一起,来使碰撞发生。如果两个刚体撞在一起,物理引擎将不会计算碰撞除非它们包含碰撞器组件

没有碰撞器的刚体,会在物理模拟中相互穿透。

Static Colliders 静态碰撞器

一个包含碰撞器但不含刚体的游戏对象,to create floors, walls and other motionless elements of a scene。

(disabled/enabled, moved or scaled during gameplay),不要在gameplay期间,做出以上()内改变,否则,改变静态碰撞器将导致物理引擎的内部计算,非常耗费资源,而且会造成性能的极大下降,更糟的是可能

扫描二维码关注公众号,回复: 1012209 查看本文章

会产生未定义的错误物理模拟现象。

***Consequently,If you want a collider object that is not affected by incoming rigidbodies but can still be moved from a script then you should attach a Kinematic Rigidbody component to it rather than no Rigidbody at all.

Continuous Collision Detection 连续碰撞检测

连续碰撞检测是为了防止快速移动 的碰撞器相互穿过的一个功能。当使用标准(Discrete)碰撞检测时,当一个碰撞器和另一个碰撞器的只有一帧的距离,并且在下一帧通过碰撞器,可能出 现这个问题。为了解决这个问题,

可以在快速移动物体的刚体上启用连续碰撞检测。设置碰撞检测模式为Continuous防止刚体通过任意静态(如,非刚 体)网格碰撞器。

设置为Continuous Dynamic也防止刚体穿过任意其他检测模式设置为Continuous 或 Continuous Dynamic的刚体。

——碰撞,触碰条件

Constant Force 恒力

Constant Force is a quick utility for adding constant forces to a Rigidbody. This works great for one shot objects like rockets, if you don't want it to start with a large velocity but instead accelerate.

恒力(Constant Force)是添加恒力到刚体的一个快速工具,对于像火箭一个发生物体,这是一个伟大的工作,如果不想启动时有很大的速度,而是慢慢加速。


A rocket propelled forward by a Constant Force 由一个恒力助推火箭向前。

Properties 属性

  • Force
    The vector of a force to be applied in world space.
    在世界空间应用的向量力。----世界坐标系
  • Relative Force 相对力
    The vector of a force to be applied in the object's local space.
    在物体的局部空间应用的向量力。---自身坐标系
  • Torque 扭矩
    The vector of a torque, applied in world space. The object will begin spinning around this vector. The longer the vector is, the faster the rotation.
    在世界空间应用的扭矩向量。该物体将开始围绕这个向量旋转。向量的时间越长,旋转速度越快。
  • Relative Torque 相对扭矩
    The vector of a torque, applied in local space. The object will begin spinning around this vector. The longer the vector is, the faster the rotation.
    在局部坐标应用的扭矩向量。该物体将开始围绕这个向量旋转。向量的时间越长,旋转速度越快。

Details 细节

To make a rocket that accelerates forward set the Relative Force to be along the positive z-axis. Then use the Rigidbody's Drag property to make it not exceed some maximum velocity (the higher the drag the lower the maximum velocity will be).

In the Rigidbody, also make sure to turn off gravity so that the rocket will always stay on its path.

为了使火箭加速前进,沿正Z轴,设置相对力。然后使用刚体的阻力属性,使其不超过最大速度(较高的摩擦力将会降低最大速度)。在刚体,也确保关闭了重力,因此火箭将总是保持其路径。

 void Rigidbody.AddForce()

给具有刚体的物体添加力,常使用的方法void Rigidbody.AddForce();有四个重载:void Rigidbody.AddForce(vector3 Force);、void Rigidbody.AddForce(Vector3 Force,ForceMode mode);

(其中第一个参数与第一个一样都是需要传入一个向量,第二个参数传入一个力的作用模式)、void Rigidbody.AddForce(float x,float y,float z);、void Rigidbody.AddForce(float x,float y,float z,ForceMode mode)(与前两个基本一样);

其中ForceMode有四种形式:ForceMode.Acceleration、ForceMode.Force、ForceMode.Impulse、ForceMode.VelocityChange。

    刚体运动速度的计算公式是:f•t=m•v

    ForceMode.Force:给物体添加一个持续的力并使用其质量。本次测试采用质量为2

    ForceMode.Acceleration::给物体添加一个持续的加速度,但是忽略其质量。即无论设置的质量为多少,都采用默认质量1

    ForceMode.Impulse;:给物体添加一个瞬间的力并使用其质量

    ForceMode.VelocityChange;:给物体添加一个瞬间的加速度,但是忽略其质量

猜你喜欢

转载自www.cnblogs.com/bananana/p/9084602.html