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

Started by
2 comments, last by alvaro 10 years, 12 months ago

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?

Advertisement

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.

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.

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.

This topic is closed to new replies.

Advertisement