navigation_different_actor_locomotion.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. .. _doc_navigation_different_actor_locomotion:
  2. Support different actor locomotion
  3. ==================================
  4. .. image:: img/nav_actor_locomotion.png
  5. To support different actor locomotion like crouching and crawling, a similar
  6. map setup as supporting :ref:`doc_navigation_different_actor_types` is required.
  7. Bake different navigation meshes with an appropriate height for crouched
  8. or crawling actors so they can find paths through those narrow sections in your game world.
  9. When an actor changes locomotion state, e.g. stands up, starts
  10. crouching or crawling, query the appropriate map for a path.
  11. If the avoidance behavior should also change with the locomotion e.g. only avoid while standing or only avoid
  12. other agents in the same locomotion state, switch the actor's avoidance agent to another avoidance map with each locomotion change.
  13. .. tabs::
  14. .. code-tab:: gdscript GDScript
  15. func update_path():
  16. if actor_standing:
  17. path = NavigationServer3D.map_get_path(standing_navigation_map_rid, start_position, target_position, true)
  18. elif actor_crouching:
  19. path = NavigationServer3D.map_get_path(crouched_navigation_map_rid, start_position, target_position, true)
  20. elif actor_crawling:
  21. path = NavigationServer3D.map_get_path(crawling_navigation_map_rid, start_position, target_position, true)
  22. func change_agent_avoidance_state():
  23. if actor_standing:
  24. NavigationServer3D.agent_set_map(avoidance_agent_rid, standing_navigation_map_rid)
  25. elif actor_crouching:
  26. NavigationServer3D.agent_set_map(avoidance_agent_rid, crouched_navigation_map_rid)
  27. elif actor_crawling:
  28. NavigationServer3D.agent_set_map(avoidance_agent_rid, crawling_navigation_map_rid)
  29. .. code-tab:: csharp
  30. private void UpdatePath()
  31. {
  32. if (_actorStanding)
  33. {
  34. _path = NavigationServer3D.MapGetPath(_standingNavigationMapRid, _startPosition, _targetPosition, true);
  35. }
  36. else if (_actorCrouching)
  37. {
  38. _path = NavigationServer3D.MapGetPath(_crouchedNavigationMapRid, _startPosition, _targetPosition, true);
  39. }
  40. else if (_actorCrawling)
  41. {
  42. _path = NavigationServer3D.MapGetPath(_crawlingNavigationMapRid, _startPosition, _targetPosition, true);
  43. }
  44. }
  45. private void ChangeAgentAvoidanceState()
  46. {
  47. if (_actorStanding)
  48. {
  49. NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _standingNavigationMapRid);
  50. }
  51. else if (_actorCrouching)
  52. {
  53. NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _crouchedNavigationMapRid);
  54. }
  55. else if (_actorCrawling)
  56. {
  57. NavigationServer3D.AgentSetMap(_avoidanceAgentRid, _crawlingNavigationMapRid);
  58. }
  59. }
  60. .. note::
  61. 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.