Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by seb-lopez · Jan 13, 2017 at 12:49 AM · aienemyaivs

freindly ai attack other ai.

Hi i made a simple ai that shoot only the player. and i was wondering how to make a Ai that actually shoot other ai's (like a huge ai battle). I'm using java, and i know we need to use an array. but i can't see what to do for making the ai attack other ai's. is there a On tags function maybe? i don't really know. can someone help please.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jwulf · Jan 13, 2017 at 03:13 AM 0
Share

How do you currently make your ai attack the player? As you have achieved that, what stops you from making it shoot something else than the player?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by seb-lopez · Jan 15, 2017 at 12:22 AM

it's for building friendly ai's to shoot the enemies ai's instead targetting me. i want to make an ai like a sand box. i want to make a script that makes me juste to put multiple ai's in a team and automatically shoot's the other team. a bit like Arma editor where you just place infentries set there teams and see the action taking place. but the problem is that i remarque that there is actually no tutorial explaining that. i know that it's array with loops but i don't know a way to implement that.

here is a turret script for the ai :

 //var player : GameObject[];
 var player : GameObject;
  var safeDist : float = 15;
  var currentDist : float;
  var shooting : boolean = false;
  var bang : AudioClip;
  var bulletFab : Rigidbody;
  var gunTip : Transform;
  var power : float = 1000;
  var shotDelay : float = 1;
 
 
  function Start (){
   player = GameObject.FindGameObjectsWithTag("blueTeam");
  }
  
  
  function Update () {
     
          currentDist = Vector3.Distance(transform.position, player.position);
      
          if(currentDist < safeDist){
              transform.LookAt(transform.position, player.position);
              if(!shooting) shootStuff();
      
          
      }
          
  }
  
  function shootStuff(){
      
      shooting = true;
      
     
      //for ( var i = 0 ; i <player.Length; i++){
          AudioSource.PlayClipAtPoint(bang, transform.position);
      
          var fwd = transform.TransformDirection(Vector3.forward);
          var bulletShot : Rigidbody = Instantiate(bulletFab, gunTip.position, gunTip.rotation);
          bulletShot.AddForce(fwd * power);
      
          yield WaitForSeconds(shotDelay);
          shooting = false;
      
    //  }
  }


what i put in "//" is where i think to put. the problem is that i think that the script was meant for one target.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by GarretLawrence · Jan 16, 2017 at 07:42 AM

Say each team has 3 AIs : (A1, A2, A3) vs (B1, B2, B3).

Say after getting list of B team, A1 focus fire on B2, only when B2 die (no matter killed by who), A1 will search for other target until no target left. Is that what you want?

If so you should do something like this

 var player : GameObject[];
 var currentTarget : Transform;
 var safeDist : float = 15;
 var currentDist : float;
 var shooting : boolean = false;
 var bang : AudioClip;
 var bulletFab : Rigidbody;
 var gunTip : Transform;
 var power : float = 1000;
 var shotDelay : float = 1;
  
  
 function Start (){
     
 }
   
   
 function Update () {
     //if target is alive/not null then shoot
     if(currentTarget)
     {
         currentDist = Vector3.Distance(transform.position, currentTarget.position);
       
         if(currentDist < safeDist){
             transform.LookAt(transform.position, currentTarget.position);
             if(!shooting) shootStuff();
         }
     }
     else //if not then search for new target
     {
         player = GameObject.FindGameObjectsWithTag("blueTeam");
         //pick random target
         if(player.Length > 0)
         {
             Random rand = new Random();
             var  n = rand.nextInt(player.Length);
             currentTarget = player[n];
         }
     }
 }
   
 function shootStuff(){
       
     shooting = true;
     AudioSource.PlayClipAtPoint(bang, transform.position);
       
     var fwd = transform.TransformDirection(Vector3.forward);
     var bulletShot : Rigidbody = Instantiate(bulletFab, gunTip.position, gunTip.rotation);
     bulletShot.AddForce(fwd * power);
       
     yield WaitForSeconds(shotDelay);
     shooting = false;
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image seb-lopez · Jan 16, 2017 at 09:25 AM 0
Share

even known that this script seems interesting( there is a problem in line 35 with "Random rand" it says that there is no ";" at the end). But i'm going to be more precise by telling like a codition :

is a ai that has a liste of target (in array ). if the target is tag == blue $$anonymous$$m. and if the ai is near of one of these targets. it will shoot them.

and vise versa

avatar image GarretLawrence · Jan 16, 2017 at 09:35 AM 0
Share

@seb-lopez well then this script does exactly what you want... I'm not sure about how Random method declared in Javascript so maybe i was wrong. You can edit the code to :

          player = GameObject.FindGameObjectsWithTag("blueTeam");
          //pick 1st target from the list
          if(player.Length > 0)
          {
              currentTarget = player[0];
          }
avatar image seb-lopez GarretLawrence · Jan 16, 2017 at 10:46 PM 0
Share

it 's saids :

i never been soo close to achieved this script =) but unfortunately it tells me : BCE0022: Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Transform'.

avatar image GarretLawrence seb-lopez · Jan 16, 2017 at 11:00 PM 0
Share

Oh sorry it should be : currentTarget = player[0].transform;

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AI passes through walls and flies 2 Answers

My Eneny AI Script Wont Work? 2 Answers

What am I doing wrong with my AI? 1 Answer

How do I make an enemy lead his shots? 2 Answers

enemy ai movement. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges