I'd like to have something like an on-screen panel that appears in the direction that you are supposed to go.

The panel is a NamMeshAgent with a speed of 0. I was hoping something like this would work:

In Start: agent.updateRotation = false;

In Update: this.transform.LookAt(agent.nextPosition);

But no luck.

Should be straight forward, I'm just not too familiar with the Unity 2019 nav mesh and can't find the answer online. Thanks.

  • 2
    \$\begingroup\$ "But no luck" is not really informative. Can you explain what happens? What is the panel - a UI element? \$\endgroup\$ – nihohit Jun 12 '19 at 8:34
  • 1
    \$\begingroup\$ How wrong does it appear, add screen shots \$\endgroup\$ – Mohammad Zamanian Jun 12 '19 at 11:39
  • \$\begingroup\$ It's not a UI element. It's an empty object containing a quad. The above code does nothing. The "panel" does not rotate. I can make the panel point towards the target destination by doing this in the Update method: this.transform.LookAt(Target.transform.position);, but I want it to point towards the next node along the navmesh path. I could take a screenshot if needed, but it's just a 3D square facing the wrong way. Not sure how relevant that would be haha. \$\endgroup\$ – JSideris Jun 12 '19 at 16:36
  • \$\begingroup\$ This is a really low quality question and should probably be closed. Your own answer doesnt fit what youre asking for in the question. It's also unclear what youre trying to achieve. NavMeshAgent's entire purpose is to move objects. Pointing an object at a position is not something that requires a NavMeshAgent. \$\endgroup\$ – Stephan Jun 13 '19 at 14:02
  • \$\begingroup\$ What? In what way does my answer not fit the question? It literally solves what I'm asking, and how can you judge the quality of a question based on the answers? The question is not how to point towards a position. The problem is how to aim at the next position in a navigation path. If you have a suggestion of how to do that without using a nav mesh agent, I'm more than open to suggestions. Not sure what would motivate you to want the question closed at this point... \$\endgroup\$ – JSideris Jun 13 '19 at 15:55

I came up with the following mediocre solution that works for me.

enter image description here

    void Start()
        agent = GetComponent<NavMeshAgent>();
        agent.destination = Target.transform.position;

    void Update()
        if(Random.value < 0.01) this.agent.Warp(Player.transform.position);

Warping every frame prevents the turning from working so I just warp it randomly. Speed and acceleration on nav mesh agent also have to be above zero... I don't like how the agent moves towards the destination, but it's okay in my case because the whole thing is a placeholder for a particle effect, so the particles (being simulated in world-space) shouldn't jitter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.