Search Unity

Navmesh Agent and Quaternions: Setting X to immovable

Discussion in 'Navigation' started by Volcanicus, Mar 23, 2019.

  1. Volcanicus

    Volcanicus

    Joined:
    Jan 6, 2018
    Posts:
    169
    I set a raycast on click script to dictate movement of my agent. My only gripe was that the agent would arc around a radius when prompted to move in a position behind him. So I added the following line:
    Code (CSharp):
    1.         if (mNav.velocity.sqrMagnitude > Mathf.Epsilon)
    2.         {
    3.             transform.rotation = Quaternion.LookRotation(mNav.velocity.normalized);
    4.         }
    On a simple X,Z plane movement, all is fine, but the trouble begins when the agent has to go up slopes and stairs. The agent will rotate erratically on the X axis (the Z axis points forward).

    Is there a way to isolate the X axis rotation to prevent this while maintaining the Y axis quick turn behaviour?

    Below are the nav mesh settings
    upload_2019-3-22_20-52-50.png

    upload_2019-3-22_20-54-8.png

    upload_2019-3-22_20-53-23.png
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Are you certain this rotation is due to the Agent, and not the result of another component like a rigidbody not set to kinematic?
     
  3. Volcanicus

    Volcanicus

    Joined:
    Jan 6, 2018
    Posts:
    169
    Yup, if I disable that part I mentioned up top, the issue doesn't happen.
    i did more testing and the way I see it, I force the character to face a certain direction based on the 3D vector of where the character is assigned to move to. I cannot seem to lock it's X rotation though.

    Here's the full character inspector's:
    There is not much else
    upload_2019-3-25_8-30-4.png
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Hold on, I believe I might see what's going on. You're directly editing your transform's rotation, which might still interfere with the agent. Then add to it that you're setting an unfiltered lookrotation, if the lookvector has even a slight deviancy this will tilt your transform. Try using Transform.RotateAround instead.
     
  5. Volcanicus

    Volcanicus

    Joined:
    Jan 6, 2018
    Posts:
    169
    I tried it but to no avail. I found that removing it but increasing the angular speed to 9001 works just as well. So scratch all that.
    Thank you for your time though Yandalf.