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

搜索資源 注冊|登陸

等待

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

unity3d視頻教程

unity3d視頻教程

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

從零基礎(chǔ)學(xué)習(xí)unity3d游戲引擎,簡單易學(xué)的視頻教程,讓你快速掌握unity3d,并喜歡上游戲開發(fā)的樂趣。

關(guān)閉

Unity組件:Box Collider 盒碰撞器

關(guān)注:3158 留言:0 樓主:zhoujunmss001 發(fā)帖時間:15年11月16日

zhoujunmss001

普通會員

zhoujunmss001

社區(qū)新人:1級

關(guān)注3405人

  • 性別

  • 年齡

    23

  • 積分

    1

  • 登陸

    1

  • 發(fā)帖

    1

  • 作品

    1

間隔線

The Box Collider is a basic cube-shaped collision primitive.

盒碰撞器是一個基本的方形碰撞原型。

盒碰撞器 Box Collider
A pile of Box Colliders 一堆盒碰撞器

Properties 屬性
  • Material 材質(zhì)
    Reference to the Physic Material that determines how this Collider interacts with others.
    引用何種物理材質(zhì)決定了他和其他對象如何作用。
  • Is Trigger 是否觸發(fā)器
    If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
    如激活,此碰撞器用于觸發(fā)事件,并且被物理引擎忽略。
  • Size 大小
    The size of the Collider in the X, Y, Z directions.
    在X、Y、Z三維上的碰撞器尺寸。
  • Center 中心
    The position of the Collider in the object's local space.
    碰撞器在對象本地坐標(biāo)中的位置
Details 細(xì)節(jié)

The Box Collider can be resized into different shapes of rectangular prisms. It works great for doors, walls, platforms, etc. It is also effective as a human torso in a ragdoll or as a car hull in a vehicle. Of course, it works perfectly for just boxes and crates as well!

盒碰撞器可以被調(diào)整成不同大小的長方體。能夠很好地用于門、墻、平臺等等。也能夠用于角色的軀干或者車輛等交通工具的外殼。當(dāng)然,只是用在盒子或者箱子上表現(xiàn)也十分完美。

A standard Box Collider 一個標(biāo)準(zhǔn)的盒碰撞器
A standard Box Collider 一個標(biāo)準(zhǔn)的盒碰撞器

Colliders work with Rigidbodies to bring physics in Unity to life. Whereas Rigidbodies allow objects to be controlled by physics, Colliders allow objects to collide with each other. Colliders must be added to objects independently of Rigidbodies. A Collider does not necessarily need a Rigidbody attached, but a Rigidbody must be attached in order for the object to move as a result of collisions.

盒碰撞器作用于剛體使Unity中的物理作用生效。因為剛體允許對象被物理系統(tǒng)控制。碰撞器使對象之間產(chǎn)生碰撞作用。碰撞器必須獨立于剛體加在對象上。碰撞器并不一定需要附加剛體,但是要使移動物體具有碰撞效果必須附加剛體。

When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them. These events can be handled in scripting, and allow you to create unique behaviors with or without making use of the built-in NVIDIA PhysX engine.

當(dāng)兩個碰撞器間產(chǎn)生碰撞并且其中至少一個附加了剛體時,三個碰撞信息會發(fā)送給附加他們的對象,這些事件可以被腳本處理,而且允許用戶可以選擇自己寫腳本或使用內(nèi)置的NVIDIA PhysX引擎創(chuàng)建唯一的行為。

Triggers 觸發(fā)器

An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!

一個可供選擇的碰撞器使用方法是標(biāo)記他們?yōu)橛|發(fā)器,僅需要選中檢視面板中的IsTrigger屬性選擇框。觸發(fā)器不受物理引擎控制,當(dāng)和一個觸發(fā)器發(fā)生碰撞時會發(fā)出三個獨特的觸發(fā)信息。觸發(fā)器用于觸發(fā)你游戲中的其他事件,比如過場動畫、自動門開啟、顯示教程信息等等,發(fā)揮你的想象力吧!

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

當(dāng)然也應(yīng)該意識到為了使兩個觸發(fā)器碰撞時發(fā)出碰撞事件,其中一個必須包含剛體。一個觸發(fā)器和一個普通碰撞器碰撞,其中之一必須附加剛體。想了解不同類型碰撞的詳細(xì)情況,可以參考下邊進(jìn)階部分中的碰撞行為矩陣。

Friction and bouncyness 摩擦力和彈力

Friction, bouncyness and softness are defined in the Physic Material. The Standard Assets contain the most common physics materials. To use one of them click on the Physic Material drop-down and select one, eg. Ice. You can also create your own physics materials and tweak all friction values.

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

Compound Colliders 復(fù)合碰撞器

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.

復(fù)合碰撞器是組合原型碰撞器,共同扮演單個碰撞器的角色。當(dāng)你在碰撞器上使用了一組復(fù)雜的網(wǎng)格而網(wǎng)格碰撞器不能用時,這是很好的選擇。要創(chuàng)建復(fù)合碰撞器,只需給你的碰撞器對象創(chuàng)建子對象,然后為每個子對象添加原型碰撞器。這就允許你輕易地移動、旋轉(zhuǎn)或者伸縮每個碰撞器,并使他們互相之間互不影響。

一個真實復(fù)合碰撞器設(shè)置
A real-world Compound Collider setup 一個真實復(fù)合碰撞器設(shè)置

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ī)則形狀構(gòu)成的地形或環(huán)境十分合適。槍模型游戲?qū)ο蟾郊恿藙傮w和多個原型碰撞器子對象。當(dāng)父級剛體受力移動時,子級碰撞器也隨之一起移動。原型碰撞器會和環(huán)境網(wǎng)格碰撞器碰撞,同時父級剛體會因子級碰撞器和場景中其他碰撞器作用產(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)格碰撞器標(biāo)記為凸起的(Convex),那么它可以和其他碰撞器碰撞。典型的解決方法是在移動對象上使用原型碰撞器而在靜態(tài)的背景對象上使用網(wǎng)格碰撞器。

Hints 提示
  • To add multiple Colliders for an object, create child GameObjects and attach a Collider to each one. This allows each Collider to be manipulated independently.
    要給一個對象添加多個碰撞器,應(yīng)該創(chuàng)建子對象并給每個子對象添加一個碰撞器。這使每個碰撞器可以被單獨操作。
  • You can look at the gizmos in the Scene View to see how the Collider is being calculated on your object.
    可以通過場景視圖(Scene View )中的線框(gizmos)來查看碰撞器在你的對象上的預(yù)期效果。
  • Colliders do their best to match the scale of an object. If you have a non-uniform scale (a scale which is different in each direction), only the Mesh Collider can match completely.
    碰撞器盡量匹配對象的比例。如果有一組不規(guī)則伸縮(每一維度上的比例都不相同),只能使用網(wǎng)格碰撞器才能完全匹配。
  • If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
    如果你想接收通過Transform組件移動的對象的碰撞/觸發(fā)信息,你必須給移動對象附件剛體。
Advanced 進(jìn)階
Collider combinations 碰撞器組合

There are numerous different combinations of collisions that can happen in Unity. Each game is unique, and different combinations may work better for different types of games. If you're using physics in your game, it will be very helpful to understand the different basic Collider types, their common uses, and how they interact with other types of objects.

Unity中有許多不同的碰撞組合。每個游戲都很獨特,不同的組合可能更好地適用于不同類型的游戲。如果你在游戲中使用了物理效果,那理解不同的基本碰撞類型會很有幫助,包括它們的常用形式及如何和其他類型的對象作用。

Static Collider 靜態(tài)碰撞器

These are GameObjects that do not have a Rigidbody attached, but do have a Collider attached. These objects should remain still, or move very little. These work great for your environment geometry. They will not move if a Rigidbody collides with them.

指的是沒有附加剛體而附加了碰撞器的游戲?qū)ο。這類對象會保持靜止或者很輕微的移動。對于環(huán)境模型十分好用,當(dāng)和剛體碰撞時而不會移動。

Rigidbody Collider 剛體碰撞器

These GameObjects contain both a Rigidbody and a Collider. They are completely affected by the physics engine through scripted forces and collisions. They might collide with a GameObject that only contains a Collider. These will likely be your primary type of Collider in games that use physics.

指的是同時附加了剛體和碰撞器的游戲?qū)ο。通過腳本的力量和碰撞完全受物理引擎的影響?梢院椭话鲎财鞯挠螒?qū)ο笈鲎病蔀槟阌螒蛑惺褂梦锢硇Ч幕绢愋团鲎财鳌?/p>

Kinematic Rigidbody Collider 運動學(xué)剛體碰撞器

This GameObject contains a Collider and a Rigidbody which is marked IsKinematic. To move this GameObject, you modify its Transform Component, rather than applying forces. They're similar to Static Colliders but will work better when you want to move the Collider around frequently. There are some other specialized scenarios for using this GameObject.

指的是同時包含碰撞器和剛體,并且激活I(lǐng)sKinematic的一類游戲?qū)ο螅苿舆@類游戲?qū)ο,要修改它的Transform組件,而不是用力。它們很像靜態(tài)碰撞器不過對于想要不停地到處移動的碰撞器很好用。這類游戲?qū)ο筮有許多其他的獨特使用情景。

This object can be used for circumstances in which you would normally want a Static Collider to send a trigger event. Since a Trigger must have a Rigidbody attached, you should add a Rigidbody, then enable IsKinematic. This will prevent your Object from moving from physics influence, and allow you to receive trigger events when you want to.

這類對象可以用于你通常希望用靜態(tài)碰撞器發(fā)出觸發(fā)事件的情形下。因為觸發(fā)器必須要有剛體,你應(yīng)該添加剛體然后啟用IsKinematic。這會阻止你的對象因物理作用而移動并且允許接收你希望得到的觸發(fā)事件。

Kinematic Rigidbodies can easily be turned on and off. This is great for creating ragdolls, when you normally want a character to follow an animation, then turn into a ragdoll when a collision occurs, prompted by an explosion or anything else you choose. When this happens, simply turn all your Kinematic Rigidbodies into normal Rigidbodies through scripting.

運動學(xué)剛體啟用與否很容易控制。這對創(chuàng)建人偶十分適用,通常,當(dāng)你希望一個角色依照動畫活動,然后由于爆炸或者其他你選擇的情況而引起的碰撞導(dǎo)致其變?yōu)槿伺。這種情況下,很簡單,只需要通過腳本將運動學(xué)剛體改為普通剛體。

If you have Rigidbodies come to rest so they are not moving for some time, they will "fall asleep". That is, they will not be calculated during the physics update since they are not going anywhere. If you move a Kinematic Rigidbody out from underneath normal Rigidbodies that are at rest on top of it, the sleeping Rigidbodies will "wake up" and be correctly calculated again in the physics update. So if you have a lot of Static Colliders that you want to move around and have different object fall on them correctly, use Kinematic Rigidbody Colliders.

如果有剛體有時候變得靜止不動了,那么它們就是進(jìn)入休眠了。意味著它們將不受物理變化影響,也就不會移動。如果你把一個運動學(xué)剛體從一個休眠的普通剛體下邊移走,那休眠的剛體就會被喚醒并重新被物理變化時時影響。所以如果你有許多希望四處移動并有不同的對象要恰好砸到它們的靜態(tài)碰撞器,那就用運動學(xué)剛體碰撞器吧。

Collision action matrix 碰撞行為矩陣

Depending on the configurations of the two colliding Objects, a number of different actions can occur. The chart below outlines what you can expect from two colliding Objects, based on the components that are attached to them. Some of the combinations only cause one of the two Objects to be affected by the collision, so keep the standard rule in mind - physics will not be applied to objects that do not have Rigidbodies attached.

基于兩個碰撞對象的配置,可以產(chǎn)生很多不同的效果。下表概括了基于附加不同組件的兩個碰撞對象所產(chǎn)生的效果。其中有些組合只能導(dǎo)致碰撞的兩個對象中的一個受到影響,.所以考慮到保持標(biāo)準(zhǔn)的規(guī)則-物理效果將不會對沒有附加剛體的對象生效。

Collision detection occurs and messages are sent upon collision
碰撞后有碰撞檢測并有碰撞信息發(fā)出
 Static Collider
靜態(tài)碰撞器
Rigidbody Collider
剛體碰撞器
Kinematic
Rigidbody Collider
運動學(xué)剛體碰撞器
Static
Trigger Collider
靜態(tài)觸發(fā)碰撞器
Rigidbody
Trigger Collider
剛體觸發(fā)碰撞器
Kinematic Rigidbody
Trigger Collider
運動學(xué)剛體觸發(fā)碰撞器
Static Collider 靜態(tài)碰撞器 Y    
Rigidbody Collider 剛體碰撞器YYY   
Kinematic Rigidbody Collider
運動學(xué)剛體碰撞器
 Y    
Static Trigger Collider
靜態(tài)觸發(fā)碰撞器
      
Rigidbody Trigger Collider
剛體觸發(fā)碰撞器
      
Kinematic Rigidbody Trigger Collider
運動學(xué)剛體觸發(fā)碰撞器
      
Trigger messages are sent upon collision
碰撞后有觸發(fā)信息
 Static Collider
靜態(tài)碰撞器
Rigidbody Collider
剛體碰撞器
Kinematic
Rigidbody Collider
運動學(xué)剛體碰撞器
Static
Trigger Collider
靜態(tài)觸發(fā)碰撞器
Rigidbody
Trigger Collider
剛體觸發(fā)碰撞器
Kinematic Rigidbody
Trigger Collider
運動學(xué)剛體觸發(fā)碰撞器
Static Collider 靜態(tài)碰撞器    YY
Rigidbody Collider 剛體碰撞器   YYY
Kinematic Rigidbody Collider
運動學(xué)剛體碰撞器
   YYY
Static Trigger Collider 靜態(tài)觸發(fā)碰撞器 YY YY
Rigidbody Trigger Collider
剛體觸發(fā)碰撞器
YYYYYY
Kinematic Rigidbody Trigger Collider
運動學(xué)剛體觸發(fā)碰撞器
YYYYYY
Layer-Based Collision Detection 基于層的碰撞檢測

In Unity 3.x we introduce something called Layer-Based Collision Detection, and is that you can now selectively tell Unity GameObjects to collide with specific layers they are attached to. For more info, you can click here

在Unity3以后版本,我們介紹了一種稱為"基于層的碰撞檢測"(Layer-Based Collision Detection)的東西,可以讓你有選擇地控制Unity對象和他們附加的特定層碰撞。點擊此處獲取更多信息。

贊0 踩0

未知用戶

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

VIP

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

回頂部

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