跳轉至內容

遊戲開發指南/理論/碰撞檢測/圓形

75% developed
來自華夏公益教科書,開放世界開放書籍

圓形與圓形碰撞檢測

[編輯 | 編輯原始碼]

這是用來檢測兩個圓形是否發生碰撞的碰撞檢測方法。此方法可直接應用於兩個球體。

在此示例中,我們需要定義一些示例變數

- 原點作為 零位置向量

- 圓形1的中心作為 位置向量

- 圓形2的中心作為 位置向量

- 圓形1的半徑,以小數表示。

- 圓形2的半徑,以小數表示。

碰撞測試

[編輯 | 編輯原始碼]
If  then:
    They are not colliding.
If  then:
    They are touching.
If  then:
    They are colliding.

如果您希望將“接觸”視為“碰撞”,則使用以下方法

If  then:
    They are not colliding.
If  then:
    They are colliding.

圓形與點碰撞檢測

[編輯 | 編輯原始碼]

這基本上是上面方法的簡化版本,因為您可以將點視為半徑為零的圓形。

在此示例中,我們需要定義一些示例變數

- 原點作為 零位置向量

- 點的位置作為 位置向量

- 圓形1的中心作為 位置向量

- 圓形的半徑,以小數表示。

碰撞測試

[編輯 | 編輯原始碼]
If  then:
    They are not colliding.
If  then:
    They are touching.
If  then:
    They are colliding.

如果您希望將“接觸”視為“碰撞”,則使用以下方法

If  then:
    They are not colliding.
If  then:
    They are colliding.


圓形與直線碰撞檢測

[編輯 | 編輯原始碼]

圓形與矩形碰撞檢測

[編輯 | 編輯原始碼]
[編輯 | 編輯原始碼]

YouTube

涵蓋“圓形與圓形”和“圓形與點”

參考資料

[編輯 | 編輯原始碼]
華夏公益教科書