Up to date

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

支援不同角色運動

../../_images/nav_actor_locomotion.png

為了支援不同的演員運動,如蹲伏和爬行,需要一個與支援 doc_navigation_ different_actor_types 類似的地圖設定。

為蹲伏或爬行的演員烘焙具有適當高度的不同導覽網格,以便他們可以找到穿過遊戲世界中這些狹窄部分的路徑。

當演員改變運動狀態時,例如站起來、開始蹲下或爬行,查詢適當的地圖以獲取路徑。

If the avoidance behavior should also change with the locomotion e.g. only avoid while standing or only avoid other agents in the same locomotion state, switch the actor's avoidance agent to another avoidance map with each locomotion change.

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)

備註

雖然可以對多個地圖立即執行路徑查詢,但迴避代理地圖切換只有在下一次伺服器同步後才會生效。