x


instructing waypoints

I am attempting to get an object to receive "heading" instructions from waypoints.

Here is the code I have written, however it does not work as I would anticipate I.E. doesn't make any apparent difference in the object's movement direction.

var movement = Vector3(.1, 0, 0);
private var waypoints : GameObject[] = GameObject.FindGameObjectsWithTag("WayPoint");
function Update () {
    transform.Translate(movement);
    for (var i = 0; i < waypoints.length; i++)
    {
        if (Vector3.Distance(transform.position, waypoints[i].transform.position) < 1)
        {
            var pointingDirection = waypoints[i].GetComponent(PointDirection);
            movement = pointingDirection.pointing;
        }
    }
}

The variable from the other object called "pointing" is a Vector3 giving an instruction similar to (-.1, 0, 0)

Thanks

more ▼

asked Jul 20 '10 at 08:33 PM

ConanHorus gravatar image

ConanHorus
61 4 4 7

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

1 answer: sort voted first

From your code you've posted, every update you'll loop through every waypoint in the array, there's nothing that says which way point is the current heading.

What you need to do is remove the loop and add a current waypoint variable and increment the current way point when you pass the distance check.

There's a simple waypoint system in Gotow's car tutorial, just scroll down to it.

http://www.gotow.net/andrew/blog/?page_id=78

more ▼

answered Jul 21 '10 at 12:01 AM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

(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:

x959
x77
x5

asked: Jul 20 '10 at 08:33 PM

Seen: 934 times

Last Updated: Jul 20 '10 at 08:54 PM