@sngdan

I’m in the process of doing an old game of the 80’s, not had much chance to get much done of late, what with other commitments getting in the way, the following is my issue I’m trying to solve

I’m trying to work out a direction for an enemy to travel up/right/down/left “depending on the marker”,

So find a route to the character based on the markers you see in the screen shot of my project, I did mange to get a result from lets say enemy On marker 6 / character on marker 35, but it takes 44 moves and it does not join the makers together. if that makes sense.

After looking at the game itself, I though A* does not fit (no obstacles as such) as it was not around at that time the game was made? so I’m using a form of as the title says Breadth First Search, I’m assuming that this is a little different than the Breadth First Search is done or my calculations as so of.

I’ve uploaded an image of the first level/map and the Breadth First Search class I designed, although I can thin same of he code down, I wanted to make it work as intended first which is does not, I could be using the complete wrong algorithm, for what i’m trying to achieve.

Hey there,

did you choose to stick to the marker approach for movement? Did you try the approach I posted?

If you want to do pathfinding, I think the marker based approach is good (possibly something you have to create in code rather than in the editor, i.e. a system that contains all waypoints and how they are connected).

To be honest, I did not go through your attachments, but maybe a simple BFS from a maze game I did can help - I added some comments for reading.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ForForum : MonoBehaviour
{
// IntVector2 - custom struct (basically a copy of Vector2 with int's)
// GetNeighbors - function to get the neighbors of the current cell

Dictionary<IntVector2, int> distanceChart = new Dictionary<IntVector2, int>();                        // this will record the distances from start to all positions on map
Dictionary<IntVector2, IntVector2> pathChart = new Dictionary<IntVector2, IntVector2>();            // this will record the / a shortest path from start to all positions on map

public void BFS(IntVector2 startPos)
{
IntVector2 currentPos = startPos;
Queue<IntVector2> frontier = new Queue<IntVector2>();

distanceChart.Clear();
pathChart.Clear();

frontier.Enqueue(currentPos);
pathChart.Add(currentPos, IntVector2.downLeft);                                            // IntVector2.downLeft = marker for start position

while (frontier.Count > 0)                                                                // have I not been everywhere
{
currentPos = frontier.Dequeue();                                                    // get position I am currently at
foreach (IntVector2 nextPos in GetNeighbors (currentPos))                            // get a list of all my neighbors
{
if (distanceChart.ContainsKey(nextPos) == false)                                // if I have not been on the neighbor cell, process
{
frontier.Enqueue(nextPos);

// here can go further logic
// i.e. stop once next enemy found
// or create a distance list to all enemy positions
}
}
}
}
}
``````

@sngdan

@JoeStrout

Hi dude sorry for not replying sooner, I’ve finally been able to get my flat back after 18months of it been rented out, so I’m in the process of painting and the like and moving back in so not much time to program BurgerTime.

Yep I’m still using the marker system as it works well, The movement of the characters with the animation is still wrong but that can be sorted out later, with maybe joe’s system or yours, it’s just getting my head around it, and understand what the hell i’m trying to achieve.

Yeah eventually the marker gameobjects will be code orientated, but I did it that way for testing an making sure it was working.

I’m not sure if the markers are a genuine Breadth First Search so it my be a version of it.

cheers

You know I just ran across this asset by our own @Schneider21 that may be just the ticket: Node Map.

I haven’t tried it yet, but it looks like it includes path-finding on the node network, which I believe is what you’re trying to do.

This is a piece of code that uses BFS to get from Node start to Node end, saving the path taken and returning it.

``````public static List<Node> Breadthwise(Node start, Node end)
{
List<Node> result = new List<Node>();
List<Node> visited = new List<Node>();
Queue<Node> work = new Queue<Node>();

start.history = new List<Node>();
work.Enqueue(start);

while(work.Count > 0)
{
Node current = work.Dequeue();
if(current == end)
{
//Found Node
result = current.history;
return result;
}
else
{
//Didn't find Node
for(int i = 0; i < current.neighbors.Length; i++)
{
Node currentNeighbor = current.neighbors[i];
if(!visited.Contains(currentNeighbor))
{
currentNeighbor.history = new List<Node>(current.history);
work.Enqueue(currentNeighbor);
}
}
}
}
return null;
}
``````

This is the class Node that goes along with the code above:

``````public class Node : MonoBehaviour {

public Node[] neighbors;
public List<Node> history;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
``````

@Razonixx

Cheers Razonixx

I never got much further with this I did however get the other 4 games working and released a Retro Game Vol.1

I will in time come back to it I’m sure, but thanks for the advice, it’s most welcome.

I think this is what I was trying to create from some doc’s I had.