2014年10月12日 星期日

[Unity] Collider

官網教學:
http://docs.unity3d.com/Manual/CollidersOverview.html


因為官網沒有圖,這次就不貼介紹了,畢竟都英文的
所以就由我來直接解釋吧

Collider就是碰撞框
物件附上碰撞框屬性之後就會賦予它偵測與其他物件碰撞的範圍和能力
有了碰撞框才能做出例如地面、牆壁、砲彈等等,能阻礙或擊中物體的效果

而碰撞框有好幾種形狀
主要有長方形、球形、膠囊型、圓柱形,比較異類的有地形碰撞框、Wheel Collider 、Mesh Collider(不知怎翻譯才好),一個物件可以利用多個碰撞框組成複雜的碰撞框,這邊想知道詳情請點上方官方教學連結

A real-world Compound Collider setup


而碰撞框自身又有兩種類型
Trigger(觸發器)和非Trigger

在設計上觸發器類型的碰撞框通常用來做事件出發的應用(簡單來說就是用來偵測玩家或物件進入指定區域)

而非觸發器類型通常就是配合Rigidbody去實做物理現象的碰撞效果(兩顆球相撞)


觸發器碰撞過程會觸發
OnTriggerEnterOnTriggerEnter is called when the Collider other enters the trigger.
OnTriggerExitOnTriggerExit is called when the Collider other has stopped touching the trigger.
OnTriggerStayOnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.
非觸發器碰撞會觸發
OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
而碰撞會不會發生其實還是有些條件的
以下是官方的碰撞發生表,不過這等到實際開始用Collider,已經有些實際上試用後的理解或困惑,再來看會比較看得懂^ ^|||

Collision detection occurs and messages are sent upon collision
Static ColliderRigidbody ColliderKinematic Rigidbody ColliderStatic Trigger ColliderRigidbody Trigger ColliderKinematic Rigidbody Trigger Collider
Static Collider Y    
Rigidbody ColliderYYY   
Kinematic Rigidbody Collider Y    
Static Trigger Collider      
Rigidbody Trigger Collider      
Kinematic Rigidbody Trigger Collider      
Trigger messages are sent upon collision
Static ColliderRigidbody ColliderKinematic Rigidbody ColliderStatic Trigger ColliderRigidbody Trigger ColliderKinematic Rigidbody Trigger Collider
Static Collider    YY
Rigidbody Collider   YYY
Kinematic Rigidbody Collider   YYY
Static Trigger Collider YY YY
Rigidbody Trigger ColliderYYYYYY
Kinematic Rigidbody Trigger ColliderYYYYYY
Rigidbodies

沒有留言:

張貼留言