Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Stay Away from target

I have an array which is filled with all the objects with the tag Enemy. When one enemy comes close to an other enemy, it has to stay away from that enemy or go around it.

This is what I have now:

foreach(Transform enemy in enemies){
    if(enemy == this.transform) continue;

    enemyPos = enemy;
    float enemyDistance = Vector3.Distance(enemy.transform.position, transform.position);

    if(enemyDistance < 8){
        transform.RotateAround (enemyPos.position, Vector3.up, 360 * Time.deltaTime);
    }
}

If enemies come close enough to each other, they will circle around each other. Also tried to use 2 cube triggers for when an enemy object touches one of the cubes, the cubed enemy wil rotate away from it. Also tried different angles. But no luck :(

I am still trying to find a solution. But if you have a better idea about this, your help is much appreceated :)

Thanks in advance!!!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You have several moving objects, and some of them may stand in the way of other objects. I would propose that you defer moving of all those objects that have a moving obstacle in front of them. When all free-moving objects are moved then try to move all other, by repeating the procedure, because in the process some objects might become free. You essentially loop through list of not-yet-moved objects until there is no change in the list.

If you don't find any new free-moving objects then deal with the rest as you like. I would suggest that you try find alternative route only for one of them, and then repeat the procedure above. It might be that when one object is unstuck then all others are unstuck as well. You may repeat this second procedure for the rest of stuck objects.

over 4 years ago · Santiago Trujillo Report

0

The following article could help you.

In short, your agent are "repulsing" each other when they are under the given distance. This is the "separation" concept in the flock. What is really interesting is that you can have a rotation that depends on the distance (ie another agent very near mean that you have to turn hard) and that you can interact with more than one agent.

in the same site, this can help you search the player. Combien the two method, and you have agents that try to catch the player while avoiding other agents.

regards Guillaume

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!