0
\$\begingroup\$

I want to write a script that can lead to something like https://gyazo.com/90d3a0ec82a41f53c831b00c403dc7df (to surround the enemy through local avoidance). i am using navmesh unity, to solve this problem i am using this code

       //targetPosition.position - this is the enemy.
       //transforms[i].position - my agents.
       //stoppingDistance = 5.

 if ((targetPosition.position - transforms[i].position).sqrMagnitude < Mathf.Pow(navMeshAgents[i].stoppingDistance, 2) )
            {
                agents[i].GetComponent<NavMeshObstacle>().enabled = true;
                agents[i].GetComponent<NavMeshAgent>().enabled = false;
            }
            else
            {
                
                agents[i].GetComponent<NavMeshObstacle>().enabled = false;
                agents[i].GetComponent<NavMeshAgent>().enabled = true;
            } 

it looks like this https://gyazo.com/d3c4e401d424cdd42b80c40fe5d3998f . please give ideas for implementing something similar to local avoidance from warcraft 3

I hope I was able to clearly describe my problem, thanks.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You may also be interested in How can I create the arriving/engaging in combat movement like in StarCraft 2? \$\endgroup\$ Commented Jun 4, 2021 at 19:48
  • \$\begingroup\$ yes it looks like a similar problem, thanks for the link \$\endgroup\$ Commented Jun 4, 2021 at 20:06
  • \$\begingroup\$ Please embed your images into the question, stack's imgur account allows animated gifs up to a certain size. \$\endgroup\$ Commented Jun 6, 2021 at 0:58

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.