• 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 Mike Z · Dec 18, 2010 at 04:55 AM · aitag

AI Script for tag like game

I have a small game (like tag). I have multiple bots that wander on the map. At any given time the nearest bot should chase the player and if tagged then the player loses. The catch is only one bot (the nearest) can be n active pursuit at one time.

Any thoughts?

Comment
Add comment · Show 3
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 FLASHDENMARK · Dec 18, 2010 at 09:45 AM 0
Share

Hmm... you proberly should use raycasting. When the player is in range,the enemy persuits.

avatar image Jesse Anders · Dec 18, 2010 at 02:35 PM 0
Share

@DanishDude: What does raycasting have to do with deter$$anonymous$$ing whether the player is in range?

avatar image FLASHDENMARK · Dec 18, 2010 at 04:15 PM 0
Share

Raycasting, is just like a "lazer beam" as you see in movies inside a banks vault. In this case, if the player comes in range, and hits the so called "beam" casted by the raycast, the player is in range.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by The_r0nin · Dec 18, 2010 at 03:15 PM

Make an empty gameobject (call it the "Warden" or something [little pun there]). On it put a script with a static variable (call it isChasing:GameObject or something) for who is chasing and a variable for the shortest distance.

Then on each enemy, cache the Warden object in a variable on Awake() (it'll save processing speed). Every .5 second or so (why do it every frame?) have the enemies check distance. If the bot's distance is less than the stored distance it sets a variable on itself to start chasing, and sends its distance to the Warden. Then Warden then sends a message to isChasing to stop chasing, and replaces the object in isChasing with the new bot and the new distance.

This way isn't the best, but it is a good way to get started. Right at the very beginning, there will be a moment when most of the bots think they are chasing (as the distance is whittled down), but then it should work like you want it to.

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 The_r0nin · Dec 18, 2010 at 03:17 PM 0
Share

Oh, and to check distance, use Vector3.Distance(enemy.transform.position, player.transform.position);

avatar image Mike Z · Dec 18, 2010 at 03:30 PM 0
Share

To be clear, I am attaching the "warden" < good pun by the way, to the main player?

Also to prevent that moment of confusion for the bots would it benefit me in any way to assign one bot as the starting bad guy?

avatar image Mike Z · Dec 18, 2010 at 03:31 PM 0
Share

ALSO pardon me if my questions seem basic but scripting is a week side for me and this is for a school assignment and I am going FAR above the requirements of the project.

avatar image The_r0nin · Dec 18, 2010 at 04:21 PM 0
Share

No, the warden is an empty game object (so that if you destroy the player object, you don't have to reset variables). You could do this on the player, if you wanted, though. And a starting bad guy would only help if he was closest to the spawn point. Staring with a default distance might help, but it means no one would chase until the first bot got within that distance.

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

No one has followed this question yet.

Related Questions

Ai Upgrade?? Possible 1 Answer

When all objects with a certain tag has been destroyed, load the next level! 3 Answers

Ai Zombie Melee Attack script. 5 Answers

Enemy following Player on uneven surface 1 Answer

ai spot you with flashligt on!!! 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