• 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 GroundHOG-2010 · Nov 25, 2010 at 09:00 PM · aicarnavigationwaypoint

How to make waypoints

Hi In the game were making we need to know how to make way points in unity. The only problem is that were all noobs and don't know how to. Please help.

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

8 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by oliver-jones · Nov 25, 2010 at 09:08 PM

Hahah, Class!

Okay, well here is what I use, all it does it allows enemies to follow a waypoint one after another

var waypoint : Transform[]; static var speed : float = 5; private var currentWaypoint : int;

 function Update () 
 {
     if(currentWaypoint < waypoint.length)
     {
         var target : Vector3 = waypoint[currentWaypoint].position;
         var moveDirection : Vector3 = target - transform.position;
         var velocity = rigidbody.velocity;

         if(moveDirection.magnitude < 1)
         {
             currentWaypoint++;
         }
         else
         {
             velocity = moveDirection.normalized*speed;
         }
     }

     rigidbody.velocity = velocity;
 }

This goes in your enemy!

This code below, goes into a game empty:

// Draw the waypoint pickable gizmo
function OnDrawGizmos () {
    Gizmos.DrawIcon (transform.position, "Waypoint.tif");
}

Now with that, what you do is create a game empty on your scene, then drag that script onto with. Where ever this point is, the enemy will walk to it. You can have more than one waypoint. Just means the enemy will walk to one waypoint, then to the other

Comment
Add comment · Show 3 · 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 oliver-jones · Nov 25, 2010 at 09:21 PM 0
Share

BTW -- the Waypoint.tif is just an image that is placed over the top of your waypoint - so you can see it. To get yours working, create a file in your project called 'Gizmos', then place a simple small image in there, then call it Waypoint.tif

avatar image shopguy · Jan 27, 2013 at 03:22 AM 0
Share

The "rigidbody.velocity = velocity;" line needs to go inside the closing brace } above it -- otherwise velocity is not defined. Normally wouldn't comment on something so obvious, but there is an incorrect answer that could misslead folks -- will comment on that also.

avatar image systemicgames · Jan 08, 2015 at 11:24 PM 1
Share

Here are some of the errors that popped up: Assets/Path.js(5,27): BCE0044: expecting ), found ';'. Assets/Path.js(5,44): BCE0043: Unexpected token: ). Assets/Path.js(11,35): BCE0044: expecting ), found ';'. Assets/Path.js(11,37): BCE0043: Unexpected token 1. Assets/Path.js(15,5): BCE0044: expecting }, found 'else'. There are many $$anonymous$$ANY more errors that came with this script. I honestly don't know what I did wrong but if you can help me fix these please tell me.

avatar image
0

Answer by Loius · Nov 25, 2010 at 09:13 PM

There are tons of different ways.

The solution above may work for you. Personally I prefer using a spline path (Bezier curves faded together, basically; the forum has a few implementations available) which represents the optimal drive line. You then have each car attempt to match their rotation to the path's direction at the closest point to the car.

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
avatar image
0

Answer by Kota · Jul 18, 2011 at 07:40 PM

Console says (unknown identifier: "velocity") Is says this for last line of code on the first script (rigidbidy.velocity = velocity;)

Comment
Add comment · Show 1 · 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 Kota · Jul 18, 2011 at 08:04 PM 0
Share

I deleted that last line but when I ran the game the cylinder that had the script attached to it didn't move

avatar image
0

Answer by devilkkw · Jul 18, 2011 at 08:21 PM

just replace rigidbody.velocity = velocity;

in rigidbody.velocity = speed;

Comment
Add comment · Show 1 · 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 shopguy · Jan 27, 2013 at 03:24 AM 0
Share

This is incorrect, please see the comment I left on that answer -- line just needs to move up a bit. If you used speed, object would move at the same speed, same direction/etc.. would not head towards waypoint at all.

avatar image
0

Answer by Tuben · Sep 12, 2012 at 09:54 PM

Hey! is there anything i can add too this script so my enemy/npc turns(rotates) too the next waypoint at the moment he only slide the wrong way to the next way point. Thanks!

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
  • 1
  • 2
  • ›

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

8 People are following this question.

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

Related Questions

Cars in City 0 Answers

Check whether car has passed a point in world space 1 Answer

How To Add AI To Car/Racer? 4 Answers

Car- can someone help me convert this to C#? 1 Answer

Steering an AI vehicle to a waypoint using float of -1 to 1? 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