朱峰社區(qū)首頁 朱峰社區(qū)

搜索資源 注冊|登陸

等待

返回 展開菜單
按功能 按軟件

Unity3D游戲制作教程

Unity3D游戲制作教程

包含5節(jié)視頻教程

本系列包含Unity3D介紹、Unity3D導出人物、Unity3D導出場景、Unity3D導出動作、游戲測試最終完成一個簡單的游戲。是一套非常完整的Unity3D游戲制作教程。

關閉

Unity組件:Rigidbody 剛體

關注:2253 留言:0 樓主:北京青云互動科技有限公司 發(fā)帖時間:15年11月16日

北京青云互動科技有限公司

普通會員

北京青云互動科技有限公司

社區(qū)新人:1級

關注2436人

  • 積分

    20

  • 登陸

    1

  • 發(fā)帖

    2

間隔線

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.

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


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

Properties 屬性
  • Mass 質(zhì)量
    The mass of the object (arbitrary units). It is recommended to make masses not more or less than 100 times that of other Rigidbodies.
    物體的質(zhì)量(任意單位)。建議一個物體的質(zhì)量不要多于或少于其他單位的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.
    若激活,該物體不再受物理引擎驅(qū)動,而只能通過變換來操作。適用于模擬運動的平臺或者模擬受鉸鏈關節(jié)連接的剛體。
  • Interpolate 插值
    Try one of the options only if you are seeing jerkiness in your Rigidbody's movement.
    當你發(fā)現(xiàn)剛體運動時抖動,可以嘗試下面的選項。
  •     None 無
    No Interpolation is applied. 不應用插值。
  •     Interpolate 內(nèi)插值
    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().
    若激活,物體將不會受碰撞或腳本施加的力而旋轉——只能調(diào)用transform.Rotate()來旋轉。
  • Collision Detection 碰撞檢測
    Used to prevent fast moving objects from passing through other objects without detecting collisions.
    碰撞檢測模式。用于避免高速物體穿過其他物體,卻未觸發(fā)碰撞。
  •     Discrete 不連續(xù)
    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).
    不連續(xù)碰撞檢測。使用不連續(xù)碰撞檢測模式來與場景中其他碰撞器進行碰撞檢測。其他物體與它的碰撞檢測,也會應用這種模式。適用于普通碰撞(這是默認的模式)。
  •     Continuous 連續(xù)
    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)
    連續(xù)碰撞檢測。使用不連續(xù)碰撞檢測來檢測與動態(tài)碰撞器(剛體)的碰撞,使用連續(xù)碰撞檢測來檢測與靜態(tài)網(wǎng)格(非剛體)的碰撞檢測。采用連續(xù)動態(tài)碰撞檢測模式的剛體碰見這類物體也將采用連續(xù)碰撞檢測模式。而與其他剛體將采用不連續(xù)碰撞檢測模式。這種模式適用于那些采用動態(tài)連續(xù)碰撞模式的物體碰撞的物體。(這對物理表現(xiàn)有很大的影響,如果你不關心與高速物體的碰撞,那么就讓其為默認的不連續(xù)模式。)
  •     Continuous Dynamic
        動態(tài)連續(xù)
    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.
    連續(xù)動態(tài)碰撞檢測。使用連續(xù)動態(tài)碰撞檢測模式來檢測與連續(xù)模式和連續(xù)動態(tài)模式的物體間的碰撞。也適用于與靜態(tài)網(wǎng)格(非剛體)的碰撞檢測。而與之碰撞的其他模式的物體,采用的是不連續(xù)動態(tài)碰撞檢測模式。適用于高速物體。
  • 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 細節(jié)

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.

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

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.

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

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來增加一個剛體組件�,F(xiàn)在,你的物體的物理屬性就設置好了,但你也可以根據(jù)需要來為其增加碰撞器或關節(jié)。

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.

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

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.

可以通過腳本增加力或力矩來控制你的剛體。通過調(diào)用剛體中的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.

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

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.

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


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
    網(wǎng)格碰撞器——從物體的網(wǎng)格創(chuàng)建一個碰撞器。不能與其他網(wǎng)格碰撞器相碰撞。
  • Wheel Collider - specifically for creating cars or other moving vehicles
    輪碰撞器——特殊的碰撞器,用于創(chuàng)建車或其他移動交通工具。
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.

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


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.

上圖中,環(huán)境里包含一個網(wǎng)格碰撞器。網(wǎng)格碰撞器的最佳適用地方是不規(guī)則形狀的地形或環(huán)境。如圖,槍模型物體包含一個剛體組件,以及數(shù)個基本碰撞器的子物體。當剛體這個父對象受力移動時,它的子碰撞器也跟著移動�;九鲎财髋c環(huán)境的網(wǎng)格碰撞器發(fā)生碰撞時,父對象的剛體也會因其子碰撞器與環(huán)境中其他碰撞器發(fā)生碰撞產(chǎn)生的力而改變運動軌跡 。

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.

網(wǎng)格碰撞器之間通常不相互碰撞,但如果一個網(wǎng)格碰撞器被標記為凸體,那么它就可以與其他網(wǎng)格碰撞器碰撞。典型的解決方案是,對移動的對象使用基本碰撞器,而對靜態(tài)環(huán)境對象使用網(wǎng)格碰撞器。

Continuous Collision Detection 連續(xù)碰撞檢測

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.

連續(xù)碰撞檢測的主要作用是避免高速物體的穿透。在不連續(xù)碰撞檢測模式下,一個高速物體的上一幀位置在一個碰撞器的一邊,而下一幀位置就穿透該碰撞器時,就發(fā)生了穿透。為了解決這個問題,你要為高速物體設置連續(xù)碰撞檢測模式。設置連續(xù)碰撞檢測模式將避免剛體穿透靜態(tài)網(wǎng)格碰撞器(該網(wǎng)格未必是剛體)。而設置為連續(xù)動態(tài)碰撞檢測將避免剛體穿透設為連續(xù)動態(tài)碰撞檢測與動態(tài)碰撞檢測的剛體。盒碰撞器、球碰撞器技膠囊碰撞器支持動態(tài)碰撞檢測。主要,連續(xù)碰撞檢測只是提供了一種穿透的保護,它保證捕獲碰撞事件,但并不保證碰撞反應的精確性。所以,當你發(fā)現(xiàn)高速物體有這方面問題時,得考慮降低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.

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

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來創(chuàng)建盒子。盒子的高為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.

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

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.

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

Hints 提示
  • The relative Mass of two Rigidbodies determines how they react when they collide with each other.
    兩個物體的相對質(zhì)量定義它們之間的碰撞反應表現(xiàn)。
  • Making one Rigidbody have greater Mass than another does not make it fall faster in free fall. Use Drag for that.
    一個質(zhì)量大的物體并不會在自由落體中下落更快。想實現(xiàn)這種現(xiàn)象請使用阻力。
  • 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.
    若你通過變換來移動一個物體,并想接受碰撞或觸發(fā)消息 ,你必須為其在移動時附加一個剛體組件。

贊0 踩0

未知用戶

2005-2025 朱峰社區(qū) 版權所有 遼ICP備2021001865號-1
2005-2025 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號

回頂部

1.復制文本發(fā)給您的QQ好友或群、微信等;好友點擊鏈接以后,轉發(fā)就成功了。 2.如朋友點擊您的鏈接,您需要需刷新一下才行;同一個好友僅能點擊一次。
購買VIP,觀看所有收費教程�。�