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

Your Answer

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

Browse other questions tagged or ask your own question.