Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Marcus · Jun 02, 2010 at 06:18 PM · aispawnshootwaypointflying

i have 2 enemies (prefabs) on the screen and only one is shooting

Hello the problem im having is with my enemies (that ive made in to a prefab) is that i can only get one to shoot from its spawn point the other enemy is shooting from the first enemy in other words when i have 2 enemies on the screen they are both shooting from the first enemies spawnpoint (dualshoot) this is the code im using on the ai.

also instead of using waypoints does anyone know how i get the ai to just flying forward.

var waypoint : Transform[];

var speed : float = 150;

private var currentWaypoint : int;

var prefabRaket:Transform;

var x : int;

var shootForce: float;

function Update () { if(currentWaypoint < waypoint.length){

var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target - transform.position;

var velocity = rigidbody.velocity;

     if(moveDirection.magnitude &lt; 5){
         currentWaypoint++;
         }


           else{
             velocity = moveDirection.normalized * speed;
         }

     }

      rigidbody.velocity = velocity;


     if(x==200) { 
         var instanceRaket = Instantiate(prefabRaket, GameObject.Find("jas/spawn3").transform.position, transform.rotation );
         instanceRaket.rigidbody.AddForce(transform.forward * -1 * shootForce);
         x=0;
     }
     x++;

}

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by StephanK · Jun 02, 2010 at 10:21 PM

You are instantiating your rockets at GameObject.Find("jas/spawn3").transform.position. I guess that's the name of you enemy object, and its probably the name of ALL enemy objects, so GameObject.Find will return the first object of that name it finds, which is in most cases the one you spawned first. Just spawn the rockets at transform.position and you should be fine.

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 superpentil · Aug 21, 2010 at 05:55 AM

make sure the target is set to you or the character the person will be playing, if you need to

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

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

No one has followed this question yet.

Related Questions

Using box collider to determine if AI should stop help 1 Answer

My AI is flying when I jump 2 Answers

OnTriggerEnter/Exit at speed 1 Answer

Help with a simple AI 2 Answers

Clearing a destination... 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