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 kidshenlong · Mar 21, 2013 at 05:12 AM · aiwaypointobstacleobstacle avoidance

New waypoint if linecast detects obstacle?

Hey guys, been doing some research and thought I'd ask on here. I'm trying to make my racing game ai a little bit more intelligent by adding some form of obstacle avoidance. The script I have is heavily based on a youtube tutorial but it essentially has the AI go form point to point. What I've managed to add is this...

     void Update()
     {
           //RaycastHit hit;
         RaycastHit hit = new RaycastHit();
         
         for(int n = 0; n < nodes.Length; n++)
         {
             
             Debug.DrawLine(nodes[n].position - Vector3.down, nodes[(n+1)%nodes.Length].position - Vector3.down, new Color(1,1,1,0.2f));
             
              if (Physics.Linecast (nodes[n].position, nodes[(n+1)%nodes.Length].position,out hit)) {
                 print("Player detected"+nodes[n]);  
                  
                 Debug.DrawLine(nodes[n].position, nodes[(n+1)%nodes.Length].position, Color.green);
                 
                 print (hit.point);
                 
                 
             }
 }
 }

So what the above script does is draw linecasts between each waypoint. What I was hoping to implement was a sort of auxiliary waypoint. So a waypoint that would be created at just outside the point of disturbance allowing it so go around any obstacles basically.

My issue now is that When the game starts it adds all the nodes to an array. Would it be possible to add an additional waypoint into the array at specific point and then get the waypoint order to be rewritten? So even if the object was mid way through following a waypoint and an obstacle jumped up at the last second it move move to the new waypoint.

I'm thinking of rewriting the script and making it a lot simpler.

Here's a link to the movement script http://pastebin.com/gpeqjGaP

but more importantly the waypoint following script.

http://pastebin.com/gwPmTYSn

I guess what I'm hoping for are some pointers for what I can change to make this possible or even if I should just start a new script...

I was thinking about instead having a raycast on the ai object and having some script that would maybe have the ship move out of the way.

Not too sure which would be better.

Thanks in advance guys :)

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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Detect when NavMesh Obstacle Carve is done? 1 Answer

Send an enemy back to its spawn point using waypoints 2 Answers

without using NavMesh, How to avoid autonomous moving agents/obstacles 1 Answer

Infinte Runner 2D - how to generate floor and obstacles? 0 Answers

iTween Help Please MoveTo not working 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