Home c# unity navmeshagent How to set a moving target?

unity navmeshagent How to set a moving target?

Author

Date

Category

Unit should always move to one goal, which moves.

using system.collections;
Using System.Collections.Genic;
using unityengine;
using unityengine.ai;
Public Class Banditmechanic: Monobehaviour {
  Navmeshagent Agent;
  Public Transform Target;
  void start () {
    agent = getComponent & lt; navmeshagent & gt; ();
    Agent.Autorepath = true;
    Agent.SetDestination (target.position);
  }
  void fixedupdate () {
 // agent.destination = target.position;
  }
}

I wrote such a code. But the unit moves Dergano (jerks), it seems to me because I constantly change the path (if you set a static goal, it moves normally). How to properly set the goal that is constantly moving?


Answer 1

void fixedupdate ()
{
  _navmeshagent.setdestination (_player.position);
}

everything works fine. Nothing twitched. Probably case in another.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions