Sign in to follow this  

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

This topic is 1732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 1732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this