茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1704352 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00010.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2014/11/23 13:14:37

剛體 Rigidbody

Date:2013-07-17 07:45

Rigidbodies enable your GameObjects to act under the control of physics. The Rigidbody can receive forces and torque to make your objects move in a realistic way. Any GameObject must contain a Rigidbody to be influenced by gravity, act under added forces via scripting, or interact with other objects through the NVIDIA PhysX physics engine.

剛體使物體能在物理控制下運動。剛體可通過接受力與扭矩,使物體像現實方式一樣運動。任何物體想要受重力影響,受腳本施加的力的作用,或通過NVIDIA PhysX物理引擎來與其他物體交互,都必須包含一個剛體組件。


Rigidbodies allow GameObjects to act under physical influence
剛體讓物體在物理影響下運動。

Properties 屬性

  • Mass 質量

    The mass of the object (arbitrary units). It is recommended to make masses not more or less than 100 times that of other Rigidbodies.
    物體的質量(任意單位)。建議一個物體的質量不要多於或少於其他單位的100倍。
  • Drag 阻力
    How much air resistance affects the object when moving from forces. 0 means no air resistance, and infinity makes the object stop moving immediately.
    當受力移動時物體受到的空氣阻力。0表示沒有空氣阻力,極大時使物體立即停止運動。
  • Angular Drag 角阻力
    How much air resistance affects the object when rotating from torque. 0 means no air resistance, and infinity makes the object stop rotating immediately.
    當受扭力旋轉時物體受到的空氣阻力。0表示沒有空氣阻力,極大時使物體立即停止旋轉。
  • Use Gravity 使用重力

    If enabled, the object is affected by gravity.
    若激活,則物體受重力影響。
  • Is Kinematic 是否是運動學
    If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform. This is useful for moving platforms or if you want to animate a Rigidbody that has a HingeJoint attached.
    若激活,該物體不再受物理引擎驅動,而只能通過變換來操作。適用於模擬運動的平台或者模擬受鉸鏈關節連接的剛體。
  • Interpolate 插值
    Try one of the options only if you are seeing jerkiness in your Rigidbody's movement.
    當你發現剛體運動時抖動,可以嘗試下面的選項。
  •     None 無
    No Interpolation is applied. 不應用插值。

  •     Interpolate 內插值
    Transform is smoothed based on the Transform of the previous frame.
    基於上一幀的變換來平滑本幀變換。
  •     Extrapolate 外插值
    Transform is smoothed based on the estimated Transform of the next frame.
    基於下一幀的預估變換來平滑本幀變換。
  • Freeze Rotation 凍結旋轉
    If enabled, this GameObject will never rotate based on collisions or forces added via script -- it will only rotate when using transform.Rotate().
    若激活,物體將不會受碰撞或腳本施加的力而旋轉——只能調用transform.Rotate()來旋轉。
  • Collision Detection 碰撞檢測

    Used to prevent fast moving objects from passing through other objects without detecting collisions.
    碰撞檢測模式。用於避免高速物體穿過其他物體,卻未觸發碰撞。
  •     Discrete 不連續
    Use Discreet collision detection against all other colliders in the scene. Other colliders will use Discreet collision detection when testing for collision against it. Used for normal collisions (This is the default value).
    不連續碰撞檢測。使用不連續碰撞檢測模式來與場景中其他碰撞器進行碰撞檢測。其他物體與它的碰撞檢測,也會應用這種模式。適用於普通碰撞(這是默認的模式)。
  •     Continuous 連續

    Use Discrete collision detection against dynamic colliders (with a rigidbody) and continuous collision detection against static MeshColliders (without a rigidbody). Rigidbodies set to Continuous Dynamic will use continuous collision detection when testing for collision against this rigidbody. Other rigidbodies will use Discreet Collision detection. Used for objects which the Continuous Dynamic detection needs to collide with. (This has a big impact on physics performance, leave it set to Discrete, if you don't have issues with collisions of fast objects)
    連續碰撞檢測。使用不連續碰撞檢測來檢測與動態碰撞器(剛體)的碰撞,使用連續碰撞檢測來檢測與靜態網格(非剛體)的碰撞檢測。採用連續動態碰撞檢測模式的剛體碰見這類物體也將採用連續碰撞檢測模式。而與其他剛體將採用不連續碰撞檢測模式。這種模式適用於那些採用動態連續碰撞模式的物體碰撞的物體。(這對物理表現有很大的影響,如果你不關心與高速物體的碰撞,那麼就讓其為默認的不連續模式。)
  •     Continuous Dynamic
         動態連續

    Use continuous collision detection against objects set to Continuous and Continuous Dynamic Collision. It will also use continuous collision detection against static MeshColliders (without a rigidbody). For all other colliders it uses discreet collision detection. Used for fast moving objects.
    連續動態碰撞檢測。使用連續動態碰撞檢測模式來檢測與連續模式和連續動態模式的物體間的碰撞。也適用於與靜態網格(非剛體)的碰撞檢測。而與之碰撞的其他模式的物體,採用的是不連續動態碰撞檢測模式。適用於高速物體。
  • Constraints 約束
    Restrictions on the Rigidbody's motion:-
    對剛體運動的約束。
  •     Freeze Position 凍結位置
    Stops the Rigidbody moving in the world X, Y and Z axes selectively.
    剛體在世界中沿所選X,Y,Z軸的移動,將無效。
  •     Freeze Rotation 凍結旋轉
    Stops the Rigidbody rotating around the world X, Y and Z axes selectively.
    剛體在世界中沿所選的X,Y,Z軸的旋轉,將無效。

Details 細節

Rigidbodies allow your GameObjects to act under control of the physics engine. This opens the gateway to realistic collisions, varied types of joints, and other very cool behaviors. Manipulating your GameObjects by adding forces to a Rigidbody creates a very different feel and look than adjusting the Transform Component directly. Generally, you shouldn't manipulate the Rigidbody and the Transform of the same GameObject - only one or the other.

剛體讓物體在物理引擎控制下運動。它可以通過真實碰撞來開門,實現各種類型的關節及其他很酷的行為。通過力來操縱物體,與直接通過變換不同,有一種不同的感覺。通常情況下,對同一物體,要麼通過剛體操縱,要麼通過變換操縱。


The biggest difference between manipulating the Transform versus the Rigidbody is the use of forces. Rigidbodies can receive forces and torque, but Transforms cannot. Transforms can be translated and rotated, but this is not the same as using physics. You'll notice the distinct difference when you try it for yourself. Adding forces/torque to the Rigidbody will actually change the object's position and rotation of the Transform component. This is why you should only be using one or the other. Changing the Transform while using physics could cause problems with collisions and other calculations.

通過變換與通過剛體操縱最大的不同在於使用了力。剛體相比於變換,能夠接受力與扭力。變換能夠控制平移和旋轉,但與物理方式的實現不同。你可以通過實踐來明顯地區分它們的不同。給剛體施加力和力矩實際也會改變物體變換組件的位置與旋轉角度。這就是為什麼在變換和剛體間,最好只選擇一種操縱方式的原因。同時使用兩種方式會導致旋轉及其他計算出現問題。


Rigidbodies must be explicitly added to your GameObject before they will be affected by the physics engine. You can add a Rigidbody to your selected object from Components->Physics->Rigidbody in the menubar. Now your object is physics-ready; it will fall under gravity and can receive forces via scripting, but you may need to add a Collider or a Joint to get it to behave exactly how you want.

剛體在受物理引擎影響之前,必須明確添加給物體。你可以通過選中物體,然後在菜單Components->Physics->Rigidbody來增加一個剛體組件。現在,你的物體的物理屬性就設置好了,但你也可以根據需要來為其增加碰撞器或關節。

Parenting 父子級

When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.

當一個物體處於物理控制中,他會以半獨立的方式隨著變換的父親的移動而移動。如果你移動父物體,那麼它會將子剛體拖向它。但是,這個剛體仍然會根據重力下落或進行碰撞反應。

Scripting 腳本

To control your Rigidbodies, you will primarily use scripts to add forces or torque. You do this by calling AddForce() and AddTorque() on the object's Rigidbody. Remember that you shouldn't be directly altering the object's Transform when you are using physics.

可以通過腳本增加力或力矩來控制你的剛體。通過調用剛體中的AddForce()和AddTorque方法。 記住,不要同時使用物理與變換。

Animation 動畫

For some situations, mainly creating ragdoll effects, it is neccessary to switch control of the object between animations and physics. For this purpose Rigidbodies can be marked
isKinematic. While the Rigidbody is marked isKinematic, it will not be affected by collisions, forces, or any other part of physX. This means that you will have to control the object by manipulating the Transform component directly. Kinematic Rigidbodies will affect other objects, but they themselves will not be affected by physics. For example, Joints which are attached to Kinematic objects will constrain any other Rigidbodies attached to them and Kinematic Rigidbodies will affect other Rigidbodies through collisions.

有些情況下,比如想實現布娃娃效果。需要剛體在動畫與物理的操縱方式間切換。這種情況下,剛體可以標記為運動學模式。當剛體標記為運動學模式,他不會受到碰撞,力及任何物理影響,它表示你必須直接通過變換的方式來操縱該物體。運動學模式的剛體會與其他物體進行物理交互,但自身不受物理影響。例如,通過關節約束那些和運動學剛體連接起來的剛體,運動學剛體影響那些與之發生碰撞的剛體。

Colliders 碰撞器


Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur. If two Rigidbodies bump into each other, the physics engine will not calculate a collision unless both objects also have a Collider attached. Collider-less Rigidbodies will simply pass through each other during physics simulation.

碰撞器是另一種組件,它和剛體一起,來使碰撞發生。如果兩個剛體撞在一起,物理引擎將不會計算碰撞除非它們包含一個碰撞器組件。沒有碰撞器的剛體,會在物理模擬中相互穿透。


Colliders define the physical boundaries of a Rigidbody 碰撞器定義剛體的物理邊界。

Add a Collider with the Component->Physics menu. View the Component Reference page of any individual Collider for more specific information:

通過菜單Component->Physics menu來添加一個碰撞器。想知道更多信息,請看參考手冊中碰撞器方面的介紹。

  • Box Collider - primitive shape of a cube
    盒碰撞器——基本形狀是個盒子。
  • Sphere Collider - primitive shape of a sphere
    球碰撞器——基本形狀是個球。
  • Capsule Collider - primitive shape of a capsule
    膠囊碰撞器——基本形狀是個膠囊。
  • Mesh Collider - creates a collider from the object's mesh, cannot collide with another Mesh Collider
    網格碰撞器——從物體的網格創建一個碰撞器。不能與其他網格碰撞器相碰撞。
  • Wheel Collider - specifically for creating cars or other moving vehicles
    輪碰撞器——特殊的碰撞器,用於創建車或其他移動交通工具。

Compound Colliders 復合碰撞器


Compound Colliders are combinations of primitive Colliders, collectively acting as a single Collider. They come in handy when you have a complex mesh to use in collisions but cannot use a Mesh Collider. To create a Compound Collider, create child objects of your colliding object, then add a primitive Collider to each child object. This allows you to position, rotate, and scale each Collider easily and independently of one another.

組合碰撞器是基本碰撞器的組合,共同扮演一個碰撞器的角色。當你有一個複雜網格卻不適用網格碰撞器的情況下,使用組合碰撞器是個好的選擇。要創建組合碰撞器,先為你的碰撞物體創建子對象,然後對每個子對像創建一個基本碰撞器。這樣就允許你輕易的獨立移動、旋轉和放縮每個碰撞器。


A real-world Compound Collider setup 一個真實的組合碰撞器的配置


In the above picture, the environment has a Mesh Collider attached. Mesh Colliders work the best for terrain or environments made from irregular shapes. The gun_model GameObject has a Rigidbody attached, and multiple primitive Colliders as child GameObjects. When the Rigidbody parent is moved around by forces, the child Colliders move along with it. The primitive Colliders will collide with the environment's Mesh Collider, and the parent Rigidbody will alter the way it moves based on forces being applied to it and how its child Colliders interact with other Colliders in the Scene.

上圖中,環境裡包含一個網格碰撞器。網格碰撞器的最佳適用地方是不規則形狀的地形或環境。如圖,槍模型物體包含一個剛體組件,以及數個基本碰撞器的子物體。當剛體這個父對像受力移動時,它的子碰撞器也跟著移動。基本碰撞器與環境的網格碰撞器發生碰撞時,父對象的剛體也會因其子碰撞器與環境中其他碰撞器發生碰撞產生的力而改變運動軌跡 。


Mesh Colliders can't normally collide with each other. If a Mesh Collider is marked as Convex, then it can collide with another Mesh Collider. The typical solution is to use primitive Colliders for any objects that move, and Mesh Colliders for static background objects.

網格碰撞器之間通常不相互碰撞,但如果一個網格碰撞器被標記為凸體,那麼它就可以與其他網格碰撞器碰撞。典型的解決方案是,對移動的對象使用基本碰撞器,而對靜態環境對像使用網格碰撞器。

Continuous Collision Detection 連續碰撞檢測


Continuous collision detection is a feature to prevent fast-moving colliders from passing each other. This may happen when using normal (Discrete) collision detection, when an object is one side of a collider in one frame, and already passed the collider in the next frame. To solve this, you can enable continuous collision detection on the rigidbody of the fast-moving object. Set the collision detection mode to Continuous to prevent the rigidbody from passing through any static (ie, non-rigidbody) MeshColliders. Set it to Continuous Dynamic to also prevent the rigidbody from passing through any other supported rigidbodies with collision detection mode set to Continuous or Continuous Dynamic. Continuous collision detection is supported for Box-, Sphere- and CapsuleColliders. Note that continuous collision detection is intended as a safety net to catch collisions in cases where objects would otherwise pass through each other, but will not deliver physically accurate collision results, so you might still consider decreasing the fixed Time step value in the TimeManager inspector to make the simulation more precise, if you run into problems with fast moving objects.

連續碰撞檢測的主要作用是避免高速物體的穿透。在不連續碰撞檢測模式下,一個高速物體的上一幀位置在一個碰撞器的一邊,而下一幀位置就穿透該碰撞器時,就發生了穿透。為了解決這個問題,你要為高速物體設置連續碰撞檢測模式。設置連續碰撞檢測模式將避免剛體穿透靜態網格碰撞器(該網格未必是剛體)。而設置為連續動態碰撞檢測將避免剛體穿透設為連續動態碰撞檢測與動態碰撞檢測的剛體。盒碰撞器、球碰撞器技膠囊碰撞器支持動態碰撞檢測。主要,連續碰撞檢測只是提供了一種穿透的保護,它保證捕獲碰撞事件,但並不保證碰撞反應的精確性。所以,當你發現高速物體有這方面問題時,得考慮降低TimeManager中的固定時間間隔來讓模擬更加的精確。

Use the right size 使用正確的大小

The size of the your GameObject's mesh is much more important than the mass of the Rigidbody. If you find that your Rigidbody is not behaving exactly how you expect - it moves slowly, floats, or doesn't collide correctly - consider adjusting the scale of your mesh asset. Unity's default unit scale is 1 unit = 1 meter, so the scale of your imported mesh is maintained, and applied to physics calculations. For example, a crumbling skyscraper is going to fall apart very differently than a tower made of toy blocks, so objects of different sizes should be modeled to accurate scale.


你的物體網格的大小要比剛體的質量更加重要。如果你發現你的剛體不像你所期望的那樣運動——慢、飄、碰撞不正確——那麼請考慮調整你的網格資源的大小。Unity的默認長度單位是1單位=1米。你導入模型的大小會被保持,並參與物理運算中。例如,一個摩天大樓倒塌的表現肯定要異於一個玩具積木搭起來的塔,所以,對不同大小物體,要用精確的比例建模。

If you are modeling a human make sure he is around 2 meters tall in Unity. To check if your object has the right size compare it to the default cube. You can create a cube using GameObject->Create Other->Cube. The cube's height will be exactly 1 meter, so your human should be twice as tall.

如果對一個人體建模,那麼保證它大概在Unity中2米高。可以和一個默認的盒子對比來判斷大小。使用 GameObject->Create Other->Cube來創建盒子。盒子的高為1米,所以你的人高度應該是它的兩倍。

If you aren't able to adjust the mesh itself, you can change the uniform scale of a particular mesh asset by selecting it in Project View and choosing Assets->Import Settings... from the menubar. Here, you can change the scale and re-import your mesh.


如果你不能自己調整網格,那你可以修改一個指定網格資源的比例,通過在項目視圖中選中它,然後在目錄裡選擇Assets->Import Settings,在這裡,你可以選擇比例,然後重新加載你的網格。

If your game requires that your GameObject needs to be instantiated at different scales, it is okay to adjust the values of your Transform's scale axes. The downside is that the physics simulation must do more work at the time the object is instantiated, and could cause a performance drop in your game. This isn't a terrible loss, but it is not as efficient as finalizing your scale with the other two options. Also keep in mind that non-uniform scales can create undesirable behaviors when Parenting is used. For these reasons it is always optimal to create your object at the correct scale in your modeling application.

如果物體在遊戲中需要實例化成不同的比例,可以調整變換組件的比例軸。這種做法的缺點是在物體實例化時,物理模擬將執行更多操作,會導致遊戲性能下降。 這不是很可怕的下降,但確實沒有採用其他兩種方法那樣有效率。此外,父對像使用一個非標準比例的物體也會產生不好的行為。所以,建議是創建物體時盡量調整好標準比例。

Hints 提示


  • The relative Mass of two Rigidbodies determines how they react when they collide with each other.
    兩個物體的相對質量定義它們之間的碰撞反應表現。
  • Making one Rigidbody have greater Mass than another does not make it fall faster in free fall. Use Drag for that.
    一個質量大的物體並不會在自由落體中下落更快。想實現這種現象請使用阻力。
  • A low Drag value makes an object seem heavy. A high one makes it seem light. Typical values for Drag are between .001 (solid block of metal) and 10 (feather).
    阻力越大,物體看起來越輕,阻力越小,物體看起來越重。阻力的典型值在0.001(磚頭)到10(羽毛)之間。
  • If you are directly manipulating the Transform component of your object but still want physics, attach a Rigidbody and make it Kinematic.
    如你直接操縱一個物體的變換同時又想擁有物理特性,那麼 為其增加一個剛體組件,並將其設為運動學模式。

  • If you are moving a GameObject through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
    若你通過變換來移動一個物體,並想接受碰撞或觸發消息 ,你必須為其在移動時附加一個剛體組件。

頁面最後更新:2012-06-18


原文出處:Rigidbody 刚体 - Unity圣典
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|