Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
支援不同角色移動方式
若要支援不同的角色移動方式(如蹲下或爬行),必須用類似於 支援不同角色型別 的地圖配置方式。
針對蹲下或爬行的角色,烘焙高度適合的導覽網格,讓角色能夠在遊戲世界中的狹窄區域順利尋路。
當角色改變移動狀態(例如站起來、開始蹲下或爬行)時,應查詢對應地圖以取得路徑。
如果避障行為也需要隨移動方式改變(例如只在站立時啟用避障,或只避開相同行動狀態的其他代理),每當角色切換移動狀態時,也應將其避障代理切換到對應的避障地圖。
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)
private void UpdatePath()
{
if (_actorStanding)
{
_path = NavigationServer3D.MapGetPath(_standingNavigationMapRid, _startPosition, _targetPosition, true);
}
else if (_actorCrouching)
{
_path = NavigationServer3D.MapGetPath(_crouchedNavigationMapRid, _startPosition, _targetPosition, true);
}
else if (_actorCrawling)
{
_path = NavigationServer3D.MapGetPath(_crawlingNavigationMapRid, _startPosition, _targetPosition, true);
}
}
private void ChangeAgentAvoidanceState()
{
if (_actorStanding)
{
NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _standingNavigationMapRid);
}
else if (_actorCrouching)
{
NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _crouchedNavigationMapRid);
}
else if (_actorCrawling)
{
NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _crawlingNavigationMapRid);
}
}
備註
雖然可以對多個地圖立即進行路徑查詢,但切換避障代理所使用的地圖僅會在下次伺服器同步後生效。