### GameDev Marketplace

#### Women's i.make.games T-shirt

$20$15

### Image of the Day Submit

IOTD | Top Screenshots

## Nearest node to START, but in the direction of GOAL?

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.

2 replies to this topic

### #1BUnzaga  Members

Posted 28 March 2013 - 02:42 PM

I have a grid of nodes, which contain a list of neighbor nodes.  I wanted to create a FindPath function, with a Start position and a Goal position (both 3d Vectors, using X and Z, UP is 0).  I can easily get the nearest node to start, and the nearest node to goal, but I wanted to also make sure these nodes are in the direction the unit would be travelling.

For example, I don't want the unit to go AWAY from the goal, and then back track toward the goal, because the 'nearest' node to him was behind him.  I'll supply a picture to make more sense.

So in this picture, you can see the 'nearest' nodes to start and goal are where the red X's are.  Start is where the spider is located, and goal is where the black arrow is pointing.  You can see, the nearest start node, is actually in the other direction of the goal, where the yellow circled one is in the direction of the goal, even though it is further than the 'nearest' one.  The same goes for the nearest goal node.

I may be making this harder than it needs to be, but I can't seem to figure out the proper maths involved to get the nodes circled in yellow as 'start' and 'goal' nodes.

Here are the things I know:

startVector

goalVector

distanceFromStartToGoal

I need to use this information, while iterating throughout the list of nodes to determine:

startNode

goalNode

While iterating, I can figure out:

nodeDistanceToGoal

nodeDistanceToStart

So using all this information, I need to determine nearest node to startVector and the nearest node to goalVector, which are also in the direction from start to goal.

Any ideas?

Posted 28 March 2013 - 03:37 PM

Don't move towards the nearest node at the beginning. Just start the pathfinding from that node, move towards the next node instead.

If the nearest node IS the goal, obviously you have to move there though ;)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #3EWClay  Members

Posted 29 March 2013 - 01:07 AM

I deal with a similar case by creating temporary nodes at the start and end positions, linking to all the surrounding nodes, then path-finding as normal.

The direction of the goal isn't necessarily the way you need to travel if an obstacle is in the way.

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.