Up to date

This page is up to date for Godot 4.3. If you still find outdated information, please open an issue.

測試與回報問題

使用實體引擎時,您可能會遇到意想不到的結果。

雖然其中許多問題可以透過配置解決,但其中一些問題是引擎錯誤造成的。有關與實體引擎相關的已知問題,請參閱「GitHub 上開放的物理相關問題<https://github.com/godotengine/godot/issues?q=is%3Aopen+is%3Aissue+label%3Atopic%3Aphysicals >” __。查看「已關閉的問題<https://github.com/godotengine/godot/issues?q=+is%3Alined+is%3Aissue+label%3Atopic%3Aphysicals>」__ 還可以幫助回答與物理引擎行為相關的問題。

高速運動的物件會互相穿透

這稱為*隧道*。在 RigidBody 屬性中啟用**連續 CD** 有時可以解決此問題。如果這沒有幫助,您可以嘗試其他解決方案:

  • 讓你的靜態碰撞形狀更厚。例如,如果您的地板很薄,玩家無法以某種方式到達下方,則可以使對撞機比地板的視覺表示更厚。

  • 根據快速移動物體的移動速度修改其碰撞形狀。物體移動得越快,碰撞形狀應該延伸到物體外部越大,以確保它能夠更可靠地與薄壁碰撞。

  • Increase Physics Ticks per Second in the advanced Project Settings. While this has other benefits (such as more stable simulation and reduced input lag), this increases CPU utilization and may not be viable for mobile/web platforms. Multipliers of the default value of 60 (such as 120, 180 or 240) should be preferred for a smooth appearance on most displays.

堆疊的對象搖擺不定

儘管看起來是一個簡單的問題,但在物理引擎中很難實作具有堆疊物件的穩定剛體模擬。這是由相互對抗的力量整合所造成的。堆疊的物體越多,彼此之間的作用力就越強。這最終會導致模擬變得不穩定,使物體無法在不移動的情況下相互堆疊。

Increasing the physics simulation rate can help alleviate this issue. To do so, increase Physics Ticks per Second in the advanced Project Settings. Note that increases CPU utilization and may not be viable for mobile/web platforms. Multipliers of the default value of 60 (such as 120, 180 or 240) should be preferred for a smooth appearance on most displays.

縮放後的物理體或碰撞形狀無法正確碰撞

Godot 目前不支援物理體或碰撞形狀的縮放。作為解決方法,更改碰撞形狀的範圍而不是更改其比例。如果您希望視覺表示的比例也會發生變化,請變更基礎視覺表示的比例(Sprite2D、MeshInstance3D...)並分別變更碰撞形狀的範圍。在這種情況下,請確保碰撞形狀不是視覺表示的子代。

由於預設資源是共享的,因此如果您不希望將變更套用至場景中使用相同碰撞形狀資源的所有節點,則必須使碰撞形狀資源唯一。這可以透過在碰撞形狀資源*更改其大小之前*在腳本中呼叫「duplicate()」來完成。

薄的物體放在地板上時會搖晃

填寫下列設定:

  • 地板的碰撞形狀太薄。

  • RigidBody 的碰撞形狀太薄。

在第一種情況下,可以透過使地板的碰撞形狀更厚來緩解這種情況。例如,如果您的地板很薄,玩家無法以某種方式到達下方,則可以使對撞機比地板的視覺表示更厚。

在第二種情況下,這通常只能透過增加物理模擬速率來解決(因為使形狀更厚會導致 RigidBody 的視覺表示與其碰撞之間脫節)。

In both cases, increasing the physics simulation rate can also help alleviate this issue. To do so, increase Physics Ticks per Second in the advanced Project Settings. Note that this increases CPU utilization and may not be viable for mobile/web platforms. Multipliers of the default value of 60 (such as 120, 180 or 240) should be preferred for a smooth appearance on most displays.

碰撞形體

在 Godot 4 中從 Bullet 到 GodotPhysics 的過渡過程中,必須從頭開始重新實作圓柱體碰撞形狀。然而,圓柱體碰撞形狀是最難支援的形狀之一,這就是為什麼許多其他物理引擎不為它們提供任何支援的原因。目前有幾個已知的圓柱體碰撞形狀錯誤。

我們目前建議對角色使用盒子或膠囊碰撞形狀。盒子通常提供最好的可靠性,但缺點是使角色佔用更多對角線空間。膠囊碰撞形狀沒有這個缺點,但它們的形狀會使精確平台變得更加困難。

車身模擬不穩定,尤其是在高速時

當物理體高速移動時,它在每個物理步驟之間行進很長的距離。例如,當在 3D 中使用 1 單位 = 1 公尺約定時,以 360 公里/小時的速度移動的車輛每秒將行駛 100 單位。在預設物理模擬速率為 60 Hz 的情況下,車輛每個物理刻度移動約 1.67 個單位。這意味著車輛可能會完全忽略小物體(由於隧道效應),而且在如此高的速度下,模擬通常幾乎沒有可用的資料。

Fast-moving vehicles can benefit a lot from an increased physics simulation rate. To do so, increase Physics Ticks per Second in the advanced Project Settings. Note that this increases CPU utilization and may not be viable for mobile/web platforms. Multipliers of the default value of 60 (such as 120, 180 or 240) should be preferred for a smooth appearance on most displays.

當物體在瓷磚上移動時,碰撞會導致碰撞

這是物理引擎中的已知問題,由物件在形狀邊緣碰撞而引起,即使該邊緣被另一個形狀覆蓋。這在 2D 和 3D 中都可能發生。

解決這個問題的最佳方法是建立一個“複合”碰撞器。這表示您可以建立一個表示一組圖塊碰撞的單一碰撞形狀,而不是單一圖塊發生碰撞。通常,您應該在每個島嶼的基礎上拆分複合碰撞器(這意味著每組接觸的圖塊都有自己的碰撞器)。

在某些情況下,使用複合對撞機還可以提高物理模擬性能。然而,由於複合碰撞形狀要複雜得多,因此這可能並非在所有情況下都能帶來淨性能優勢。

當一個物體接觸另一個物體時影格率下降

這可能是由於其中一個物件使用的碰撞形狀過於複雜。出於性能原因,凸碰撞形狀應使用盡可能少的形狀。當依賴 Godot 的自動產生時,您最終可能會為單一凸形碰撞資源建立數十個甚至數百個形狀。

在某些情況下,用幾個原始碰撞形狀(盒子、球體或膠囊)替換凸碰撞體可以提供更好的性能。

使用非常詳細的修剪網格(凹面)碰撞的靜態物體也會出現此問題。在這種情況下,使用關卡幾何體的簡化表示法作為碰撞器。這不僅會顯著提高物理模擬性能,而且還可以透過讓您從碰撞考慮中刪除小型固定裝置和裂縫來提高穩定性。

Framerate suddenly drops to a very low value beyond a certain amount of physics simulation

This occurs because the physics engine can't keep up with the expected simulation rate. In this case, the framerate will start dropping, but the engine is only allowed to simulate a certain number of physics steps per rendered frame. This snowballs into a situation where framerate keeps dropping until it reaches a very low framerate (typically 1-2 FPS) and is called the physics spiral of death.

To avoid this, you should check for situations in your project that can cause excessive number of physics simulations to occur at the same time (or with excessively complex collision shapes). If these situations cannot be avoided, you can increase the Max Physics Steps per Frame project setting and/or reduce Physics Ticks per Second to alleviate this.

遠離世界原點時實體模擬不可靠

這是由浮點精度誤差引起的,當物理模擬遠離世界原點時,浮點精度誤差變得更加明顯。此問題也會影響算繪,導致遠離世界原點時相機移動不穩定。請參閱:ref:doc_large_world_座標 以了解更多資訊。