2014-04-01 83 views
1

我知道Unity有很多解決枯萎問題的方法,一個對象位於另一個對象內部,不管是否觸摸等,但我想知道的是更具體的東西。Unity Sphere碰撞

在我的研究中,我發現了約Physics.OverlappedSphere,並且從我能讀到的內容中可以得到有關球體內每個物體與對撞機的信息。我想知道的是,如果我有兩個使用Physics.OverlappedSphere的球體,我能找出這些球體在哪個點匯合並相交嗎?

如果這是不可能的,有人可以建議另一種方式,我可能會找到這些信息嗎?

回答

2

如果使用碰撞類和其中的Collision.contacts(這是contactpoints數組),你應該能夠...

Taken from here

function OnCollisionStay(collision : Collision) { 
    for (var contact : ContactPoint in collision.contacts) { 
     print(contact.thisCollider.name + " hit " + contact.otherCollider.name); 
     // Visualize the contact point 
     Debug.DrawRay(contact.point, contact.normal, Color.white); 
    } 
} 

嘗試獲得的大小聯繫陣列並查看最後幾點。

// Print how many points are colliding this transform 
// And print the first point that is colliding. 
function OnCollisionEnter(other : Collision) { 
    print("Points colliding: " + other.contacts.Length); 
    print("First point that collided: " + other.contacts[0].point); 
}