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.

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

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.

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

just replace rigidbody.velocity = velocity;

in rigidbody.velocity = speed;

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!

Hi,

How can I make a loop in the waypoints Transform ?

Right now the Enemy is doing:
0>1>2>3>4>5
And I’d like him to do:
0>1>2>3>4>5>0 and continue looping.

Any idea ?

Hey guys…my first post WOOT WOOT!
I just figured out today how to make AI rotate towards waypoint, So I will share with you guys. Just add:

transform.LookAt(waypoint[currentWaypoint]);

Under where you declare the variables in the first if statement.

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!