# Node Based Navigation - find closest node in direction

Discussion in 'Navigation' started by Sickscore, Apr 7, 2018.

1. ### Sickscore

Joined:
Nov 25, 2016
Posts:
12
Hey everyone,

I ran into a problem which I can't solve for a few hours now...
I'm building like a node-based navigation system, where the player will be navigated from node to node.
When I set a new target destination (red T), the player (green P) should find the closest node in the direction of the target. At the end, the player would get the shortest path (blue line) to the target. This path will be different depending on the players current position.

I tried several methods, but couldn't get it to work. My issue is not the code, it's the logic I can't get right now

The best I can think of right now is to build 2 lists from all nodes:
- first list will be ordered by distance to player
- second list will be ordered by distance to target
Then compare the two lists and get the best match of both lists? There should be a better solution to this, right?!?

Summary:
- Get closest node to player (Vector3.sqrMagnitude)
- Check if closest node is closest towards target?
- Check if there is a better node available?

Any suggestions I could try?

Best, Markus

File size:
8.9 KB
Views:
470
2. ### OneManBandGames

Joined:
Dec 7, 2014
Posts:
207
Did you consider the A* algorithm? I'm no expert on pathfinding algorithms, but your problem sounds like it could be solved with A*.

Sickscore likes this.
3. ### Sickscore

Joined:
Nov 25, 2016
Posts:
12
Hmm...I don‘t think I can use A* for this, because the nodes can be places everywhere without a fixed grid for the algorithm to work with. Maybe project the nodes onto a virtual grid? :/

4. ### rakkarage

Joined:
Feb 3, 2014
Posts:
683
Sickscore likes this.
5. ### Sickscore

Joined:
Nov 25, 2016
Posts:
12
Oh yeah, you're right. Let me do some tests, but I'm sure this will work. Thanks to both of you!

Joined:
Feb 3, 2014
Posts:
683