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期間,做出以上()內改變,否則,改變靜態碰撞器將導致物理引擎的內部計算,非常耗費資源,而且會造成性能的極大下降,更糟的是可能

會產生未定義的錯誤物理模擬現象。

***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的剛體。

 

Friction and bouncyness 摩擦力和彈力

riction, bouncyness and softness are defined in the Physic Material.

摩擦力、彈力和柔軟度由物理材質中定義。標准資源( Standard Assets)中包含了大部分常見的物理材質。要使用只需點擊物理材質上的下拉箭頭然后選中一個,比如冰。你也可以創建你自己的物理材質並調整摩擦力的大小。

 

 Mesh Collider--網格碰撞器

通常,兩個網格碰撞器之間不會發生碰撞。所有的網格碰撞器可以和任何原始碰撞器碰撞。如果網格標記為凸起的(Convex),那么就可以和其他網格碰撞器碰撞。

除非被標記為凸起的(Convex),否則網格碰撞器間不會發生碰撞。因此,它們最常被用於背景對象比如環境布景。

原型控制器(Primitive Colliders)對於對象的物理控制更加節省資源。

要給一個對象添加多個碰撞器,應該創建子對象並給每個子對象添加一個碰撞器。這使每個碰撞器可以被單獨操作。

Mesh Colliders that do not have Convex enabled are only supported on GameObjects without a Rigidbody component. To apply a Mesh Collider to a Rigidbody component, tick the Convex checkbox.

未勾選Convex的Mesh Colliders只支持不含剛體組件的對象。若要給剛體組件對象應用Mesh Collider,記得勾上Convex 選框!

 

 

 

——碰撞,觸碰條件

 

Physic Material 物理材質

物理材質用來調節碰撞物體的摩擦力和彈力效果,要創建物理材質從菜單欄選擇Assets->Create->Physic Material。然后從項目視圖拖拽物理材質到場景的一個碰撞器上。

There is a special case when the two colliders in contact have different combine modes set. In this particular case, the function that has the highest priority is used. The priority order is as follows:

Average < Minimum < Multiply < Maximum. For example, if one material has Average set but the other one has Maximum, then the combine function to be used is Maximum, since it has higher priority. 

 

Wheel Collider:鏈接

 

 

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;:給物體添加一個瞬間的加速度,但是忽略其質量

 

奧斯丁


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM