Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Navmesh agent not facing walking destination

Discussion in 'Scripting' started by Omegand, Mar 22, 2021.

  1. Omegand

    Omegand

    Joined:
    Feb 15, 2020
    Posts:
    8
    I am using a navmesh agent for my AI, but while walking it just doesn't rotate correctly? It does some rotations, but it doesn't rotate to face his movement vector, using transform.lookat doesn't do anything
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,065
    Make sure your character is laid out so that:

    1. when placed in a scene with rotations (0,0,0)

    2. the "forward" is going towards the world +Z
     
    Last edited: Mar 22, 2021
  3. Omegand

    Omegand

    Joined:
    Feb 15, 2020
    Posts:
    8


    Here's how it looks, every 4 seconds it gets a new random .setdestination to the navmesh agent, but it doesn't rotate. Yes the character is rotation 0,0,0 at the start. Not sure what "forward" world is in this scenario
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,065
    Whatever that is going on, I like it! Neat spooky forest surroundings.

    The NavMeshAgent should be turning you towards motion, but it's possible this is no longer the case, or that it is a settable option in the NavMeshAgent. I haven't used one lately so take a look in the inspector for it.

    It's also possible that something else is forcing your geometry to rotate in a particular way. To me it looks incorrectly tilted, but I'm not sure what exactly you're going for.

    To isolate further, make another character with a Unity box or something and see what it does when told to go places in the navmesh.
     
  5. Omegand

    Omegand

    Joined:
    Feb 15, 2020
    Posts:
    8
    It worked fine on a new cube, but somehow didn't work on the model so I checked the behavior code and turns out I was rotating the player to face the camera and not it's UI. Well that's unlucky
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,065
    It always feels good when investigation turns up real results.

    Or is it perhaps a new opportunity to think about how you can design into this!