View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Following a path, determining when to move on to the next point

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1JohnnyLightwave  Members

Posted 19 April 2013 - 04:18 PM

Hi all,

Using A*, I have an object that is following a list of points.

Because the object's speed and actual path is somewhat variable (it only follows the general vicinity of the points), I am looking for a good way to determine if it has passed one point and should move on to the next.

I thought I could do this with the dot product, to check the old vector toward the point with the new one, like so:

oldVector=objectTravelVector;
objectTravelVector=chasingPoint-objectPoint;
objectTravelVector.Normalize();

if (oldVector.Dot(objectTravelVector)<0) // Move to next point


It seems like that should work, but I am getting instances of my object circling points and refusing to move on to the next one.  It seems that if I pass the point, my dot product with the previous vector should be negative, and I just say, okay, next, point.

Am I doing this wrong?

### #2NumberXaero  Prime Members

Posted 19 April 2013 - 06:21 PM

What if you created a plane out of the target point and the current travel vector, then test if the current object position is on the positive side of the plane, which would mean you passed the target point.

### #3JohnnyLightwave  Members

Posted 20 April 2013 - 02:09 PM

Well, that's kinda what I'm doing, isn't it?

If the new vector is in the same direction as the old vector, then my dot should be >0, and if it's in the opposite direction (indicating passing the point), then my dot is <0 ... theoretically.

### #4Álvaro  Members

Posted 20 April 2013 - 02:31 PM

You should debug your program and monitor the values of the variables involved and the dot product while you get into the undesired circling behavior. You could also just trigger going to the next point when you are within some radius of the current point (duh).

Depending on the particulars of your game, you may want to start targeting the next point as soon as you have an unobstructed line to it. You can actually skip a bunch of points if you have a line to a later point.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.