x


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.

more ▼

asked Nov 25, 2010 at 09:00 PM

avatar image

GroundHOG-2010
1 1 2 2

(comments are locked)
10|3000 characters needed characters left

8 answers: sort voted first

Hey is it possible too add somthing too this script so the enemy/npc turn(rotate) too the next waypoint? mine is currently only sliding too the next one. thanks!

more ▼

answered Sep 12, 2012 at 09:54 PM

avatar image

Tuben
1 2

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Nov 25, 2010 at 09:08 PM

avatar image

oliver-jones
4k 727 1195 712

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

Nov 25, 2010 at 09:21 PM oliver-jones

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.

Jan 27, 2013 at 03:22 AM shopguy

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 MANY 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.

Jan 08 at 11:24 PM systemicgames
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Nov 25, 2010 at 09:13 PM

avatar image

Loius
15.1k 39 55 97

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jul 18, 2011 at 07:40 PM

avatar image

Kota
-4 13 10 12

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

Jul 18, 2011 at 08:04 PM Kota
(comments are locked)
10|3000 characters needed characters left

just replace rigidbody.velocity = velocity;

in rigidbody.velocity = speed;

more ▼

answered Jul 18, 2011 at 08:21 PM

avatar image

devilkkw
357 26 21 35

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.

Jan 27, 2013 at 03:24 AM shopguy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1486
x626
x252
x198

asked: Nov 25, 2010 at 09:00 PM

Seen: 25372 times

Last Updated: Jan 08 at 11:24 PM