Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
支援不同角色運動¶
為了支援不同的演員運動,如蹲伏和爬行,需要一個與支援 doc_navigation_ different_actor_types 類似的地圖設定。
為蹲伏或爬行的演員烘焙具有適當高度的不同導覽網格,以便他們可以找到穿過遊戲世界中這些狹窄部分的路徑。
當演員改變運動狀態時,例如站起來、開始蹲下或爬行,查詢適當的地圖以獲取路徑。
如果迴避行為也應該隨著運動而變化,例如僅在站立時迴避或僅迴避處於相同運動狀態的其他代理,則隨著每次運動變化將演員的迴避代理切換到另一個迴避地圖。
func update_path():
if actor_standing:
path = NavigationServer3D.map_get_path(standing_navigation_map_rid, start_position, target_position, true)
elif actor_crouching:
path = NavigationServer3D.map_get_path(crouched_navigation_map_rid, start_position, target_position, true)
elif actor_crawling:
path = NavigationServer3D.map_get_path(crawling_navigation_map_rid, start_position, target_position, true)
func change_agent_avoidance_state():
if actor_standing:
NavigationServer3D.agent_set_map(avoidance_agent_rid, standing_navigation_map_rid)
elif actor_crouching:
NavigationServer3D.agent_set_map(avoidance_agent_rid, crouched_navigation_map_rid)
elif actor_crawling:
NavigationServer3D.agent_set_map(avoidance_agent_rid, crawling_navigation_map_rid)
備註
雖然可以對多個地圖立即執行路徑查詢,但迴避代理地圖切換只有在下一次伺服器同步後才會生效。