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 POLYGAMe · Feb 15, 2012 at 06:19 AM · aiwaypoints

AI Car Waypoints - Odd Behaviour...

Hi there,

I am trying to set up a basic system in which my AI cars drive around the track, by way of waypoints. I thiought this would be simple, but the code that I have isn't working... each time the car hits a waypoint, it slows down and moves to the next. It only gets to a couple of waypoints before coming to a complete stop... any ideas?!?!?!

 for (var i = 0; i < Waypoints.length - 1; ++i)
             {
                  transform.position = Vector3.MoveTowards(transform.position,Waypoints[i].transform.position,(fSpeed * Time.deltaTime));
                  
              }
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 POLYGAMe · Feb 15, 2012 at 06:36 AM 0
Share

Actually... looking at it closely, it's only moving to the second waypoint... and it slows down.... REALLY weird...

avatar image POLYGAMe · Feb 15, 2012 at 06:45 AM 0
Share

Silly me, it's counting through the index every frame, but it takes time to perform the transform.Translate. DUH. I just need to make it wait until a waypoint is hit before it moves to the next. I'll be up all night, I know it... DA$$anonymous$$N $$anonymous$$Y NOOBNESS!!!!!

avatar image POLYGAMe · Feb 15, 2012 at 06:57 AM 0
Share

It also helps if you turn on the box colliders. DOH. FIXED!!!!!

1 Reply

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

Answer by POLYGAMe · Feb 15, 2012 at 07:20 AM

For anyone else interested in this, here is what I did:

I got rid of the for loop and put an OnTriggerEnter function that when triggered (by car hitting waypoint), increments the waypoint array index. This way, every time a waypoint is hit, the car moves on to the next :)

It's really basic and needs a LOT of waypoints to be reasonably smooth but for a simple game like mine, it's fine.

Hope this helps someone else!!!

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 jorjdboss · Aug 03, 2012 at 08:56 AM 0
Share

Can the triggers overlap? what if gets stuck inside a trigger. What about steep corners < 90 degrees? Is this method better than checking distance between player and waypoint and changing the waypoint to the next one and keep doing the same over and over again?

avatar image POLYGAMe · Aug 03, 2012 at 09:25 AM 0
Share

Haha, nah... found it had a load of bugs (unless you have VERY basic tracks). We went with the distance method ;-)

Basically we ended up with WAY less waypoints and lerped between them. $$anonymous$$uch smoother.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make an AI of a car to jump if there is any obstacle 2 Answers

Enemy AI things to consider 2 Answers

Help With Waypoints script 1 Answer

Smooth turn.... 1 Answer

How do I spawn unique Waypoints for my AI? 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