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...
支持不同角色运动

要支持不同的角色运动,比如下蹲和爬行,需要和支持 支持不同角色类型 一样的地图设置。
为蹲伏或爬行的演员烘焙具有适当高度的不同导览网格,以便他们可以找到穿过游戏世界中这些狭窄部分的路径。
当 actor 改变运动状态时,例如站起来、开始蹲下或爬行,查询适当的地图以获取路径。
如果回避行为也应该随着运动而改变,例如仅在站立时回避或仅避开处于相同运动状态的其他代理,则随着每次运动的改变,将参与者的回避代理切换到另一个回避图。
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);
}
}
备注
虽然可以对多个地图立即执行路径查询,但回避代理地图切换只有在下一次服务器同步后才会生效。