支持不同角色运动

../../_images/nav_actor_locomotion.png

要支持不同的角色运动,比如下蹲和爬行,需要和支持 支持不同角色类型 一样的地图设置。

Bake different navigation meshes with an appropriate height for crouched or crawling actors so they can find paths through those narrow sections in your game world.

When an actor changes locomotion state, e.g. stands up, starts crouching or crawling, query the appropriate map for a path.

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 actors’s avoidance agent to another avoidance map with each locomotion change.

GDScript

  1. func update_path():
  2. if actor_standing:
  3. path = NavigationServer3D.map_get_path(standing_navigation_map_rid, start_position, target_position, true)
  4. elif actor_crouching:
  5. path = NavigationServer3D.map_get_path(crouched_navigation_map_rid, start_position, target_position, true)
  6. elif actor_crawling:
  7. path = NavigationServer3D.map_get_path(crawling_navigation_map_rid, start_position, target_position, true)
  8. func change_agent_avoidance_state():
  9. if actor_standing:
  10. NavigationServer3D.agent_set_map(avoidance_agent_rid, standing_navigation_map_rid)
  11. elif actor_crouching:
  12. NavigationServer3D.agent_set_map(avoidance_agent_rid, crouched_navigation_map_rid)
  13. elif actor_crawling:
  14. NavigationServer3D.agent_set_map(avoidance_agent_rid, crawling_navigation_map_rid)

备注

While a path query can be execute immediately for multiple maps, the avoidance agent map switch will only take effect after the next server synchronization.

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.