• 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 polilla19 · Jan 30, 2013 at 01:59 PM · aishootscrpt

AI Shooter

I need a script that makes a character (No animation, like it was a simple cube) to be in some waypoints (I dont how to make waypoints) and in a certain distance of my player, shoot at me at a certain speed. Please, Im a noob, can someone tell me what to do and give the scrip??????????

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 Loius · Jan 30, 2013 at 02:19 PM 0
Share

Nope. All that information is already on the internet, and I can guarantee that each of your questions has been answered, extremely well, multiple times on this site in particular. Google's a great search engine.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Jan 30, 2013 at 02:15 PM

I'm not going to give you a script, but I'll give you some ideas that you can research and learn about:

  1. Waypoints can be stored in a List or Array. A waypoint is basically a position, you can have a list or array of Vector3 structs to keep track of the position.

  2. A good way to move an object between waypoints is the Vector3.Lerp function. This will move the object from one position to another over time.

  3. You can use Vector3.Distance to calculate the distance between two positions (e.g. your player and one of the objects)

  4. If that distance is below a certain value then start shooting, but let's save that part for later - get things moving first, then maybe come back and ask for advice on the shooting part.

Start small. Get a cube on the screen, create two variables with two different positions, and get the cube moving between them using Lerp. Those two variables are basically your waypoints.

Comment
Add comment · Show 4 · 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 polilla19 · Jan 30, 2013 at 02:23 PM 0
Share

thanks, but how do i make it shoot

avatar image Dave-Carlile · Jan 30, 2013 at 02:26 PM 0
Share

Like I said, get the other things working first. No need to confuse the issue when you're starting out.

avatar image polilla19 · Jan 31, 2013 at 01:19 PM 0
Share

okay i made it move between the waypoints but it only moves 1 time, what do i do now, should i put de Vector.Distance or what?

avatar image $$anonymous$$ · Jan 31, 2013 at 01:41 PM 1
Share

You should seriously do some tutorials... there are SO $$anonymous$$ANY good tutorials on youtube, you just follow along and they explain things pretty well... I can't comprehend why people tend to skip this part... compared to other game engines, Unity has a tremendously active and helpful community, the only one I could compare it to is UD$$anonymous$$, but for example if you were to start out with CryEngine, you would be almost totally helpless. Google and Tutorials are good for your health, and there's PLENTY.

Try these, or anything else: http://www.youtube.com/feed/UCV0Jhu5jv9OsV19TmqHEt_g

avatar image
0

Answer by Tim-A · Jan 31, 2013 at 01:30 PM

To shoot, you would need to do this,

 var target : Transform;
    var distance : float;
 function Update () {
     target = GameObject.FindWithTag("Player").transform;
     if(target){
     var dist = Vector3.Distance(target.position, transform.position);
              if(dist >= distance){
                     //Your shoot script here.
                        }
                     }
                  }

Set target as your target you want to shoot, and distance to how close you have to be until you shoot.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Make AI enemies react to bullet hits (Solved) 0 Answers

how to make an enemy Ai blow up when you shoot it? 2 Answers

enemy shoot AI precision 1 Answer

Auto shooting script. 1 Answer

AI problems ( enemy doesn't shoot ) 2 Answers


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