4 Navigation
Mikulas Florek edited this page 2021-03-13 13:01:27 +01:00

There are several ways to do navigation depending on whether animation or physics is involved. Zones are related to all of them.

Zones

  1. create an entity
  2. add navigation / zone component
  3. set desired size
  4. click generate in property grid
  5. click save in property grid to save the recently generated navmesh data

navigation zone in property grid

You can check Draw navmesh in property grid to make sure your navmesh is correct

No animation, no physics

  1. creat an entity, the entity must be inside navigation zone
  2. add navigation / agent component
  3. add lua script component
  4. call this.navmesh_agent:navigate(destination, 10, 1) in agent's script

You can see demo as an example.

Animation and physics

  1. creat an entity, the entity must be inside navigation zone
  2. add navigation / agent component
  3. uncheck Move entity, so navmesh agent won't try to move entity directly
  4. add physics / controller component
  5. check use root motion, controller will try to get root motion for animation system and apply it
  6. add animation / animator component and set some graph with root motion to it
  7. in code, you have to get speed and angle from navigation system and set it to animation system, for example like this:
    float speed = m_navigation_scene->getAgentSpeed(e);
    float dir = -m_navigation_scene->getAgentYawDiff(e);
    const i32 dir_idx = m_ani_scene->getAnimatorInputIndex(e, "dir");
    const i32 speed_idx = m_ani_scene->getAnimatorInputIndex(e, "speed");
    m_ani_scene->setAnimatorInput(e, dir_idx, dir);
    m_ani_scene->setAnimatorInput(e, speed_idx, speed);