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 FinKone · Jul 11, 2013 at 04:22 PM · raycastaiwaypoint

Using box collider to determine if AI should stop help

Hey guys. Situation - I have civilian AI roam around randomly from waypoint to waypoint - they use raycast to avoid one another - which works pretty decent, but sometimes 2 AI reach the node around the same time, and also attempt to head to the next waypoint at the same time, they stack into each other... I attempted to put a box collider on them as a child so they would stop if following to close until the exit happens from the other one they are following, and to prevent them from stacking into one another, but this just generated a few more problems.

AI will now run into each other, the colliders will both register and the never-ending face off happens. I lack the logic on my part to figure out a system where the AI will stop and allow another to move away, and then keep on his path... because they both are using the same collider on the same layer.

Here is a simple snip of the script I'm using to talk to my AI script (just using the speed var in there to force the stop)

 using UnityEngine;
 using System.Collections;
 
 public class AIStop : MonoBehaviour {
     private bool wait;
     public AI ai;
 
     void Start () {
         wait = false;
     }
 
     void Update () {
         if (wait)
         {
             ai.speed = 0f;    
         }
         else{
             ai.speed = 5f;
         }
     
     }
     
     void OnTriggerEnter(Collider AIPED)
     {
         wait = true;
     }
     void OnTriggerExit(Collider AIPED)
     {
         wait = false;
     }
 }
 

Without this weak attempt a collider if I keep the population low they appear to work fine because the chance of them getting to the same waypoint at the same time is low - but thats a workaround, not a solution... just interested to hear other peoples approaches and ideas.

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

1 Reply

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

Answer by markedagain · Jul 11, 2013 at 04:26 PM

Hey ,

Since you know who you are colliding with for example AIPED then you can do something of the sort

 if (AIPED.getComponent<AIStop>().wait == true){
 wait =false;
 }else{
 wait = true;
 }
Comment
Add comment · Show 2 · 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 fafase · Jul 11, 2013 at 04:31 PM 0
Share

You are about to hit a getComponent is not a member of Collider and then a NullReferenceException on the second and fourth line. But more than that even if you store the component you are still about to get a "wait is not accessible due to its protection level" (or something like this) You need to store the component reference and simply:

 AIStop script = AIPED.transform.GetComponent<AIStop>();
 script.wait = !script.wait;

and make sure wait is public to be seen outside the class or use a getter method.

avatar image markedagain · Jul 11, 2013 at 04:35 PM 1
Share

ya its sad how much i rely on auto complete, but i was just showing the logic behind it. i dont like this method anyway as u cant control who does the actual waiting, but u can simply put some distance check to see who is closer and have the other person wait

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

16 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

Related Questions

WayPoints mixed with Raycast 1 Answer

Not sure what this error means? 1 Answer

How to create waypoint between two gameobjects according to variable value? 0 Answers

AI Evasion help 1 Answer

Way Point Script Change Group 0 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