Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to give a 3D object a 2d sprite that doesn't rotate with Navmesh agent?

Discussion in 'General Graphics' started by Th0masThe0bvious, Feb 5, 2023.

  1. Th0masThe0bvious

    Th0masThe0bvious

    Joined:
    Aug 22, 2018
    Posts:
    80
    Hello.

    I have been making a game that has a similar graphic style to the Paper Mario games; that is, the environments are 3d but the characters are 2D sprites, and even when they "rotate" it's actually the same angle but different animations. While it is easy to implement objects that have 2D sprites and 3D colliders, that gets more iffy when Navmesh is added, as Navmesh agents rotate as they move.

    I have some ideas about how to accomplish my goal in a roundabout way, but is there a faster and more direct one?
     
  2. RafaelGomes00

    RafaelGomes00

    Joined:
    Aug 13, 2020
    Posts:
    73
  3. gwyrwasEICC

    gwyrwasEICC

    Joined:
    Mar 1, 2021
    Posts:
    19
    Navmesh agents have two properties that can be adjusted to disable rotation, NavMeshAgent.updateRotation and NavMeshAgent.angularSpeed. These can be set to false and 0 respectively to stop your object from rotating while travelling across its path.
     
  4. Th0masThe0bvious

    Th0masThe0bvious

    Joined:
    Aug 22, 2018
    Posts:
    80
    Thanks a bunch; that worked great!

    Hey, while we're here: Is there a way to get my NavMesh's movement to influence what sprite animation plays?
     
  5. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    There is no built-in feature to do that. But certainly yes it is possible to program such a feature yourself. Though it can be a bit tricky. Unity's builtin NavMesh system has very limited events that you can hook into so you usually end up infering things based on tracking the motion over time as well as writing your own wrapper layer for the whole thing.