Advertisement Jump to content
Sign in to follow this  

Path Finding Potential Field problem

This topic is 2244 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

I'm writing my own path finding, aimed at guiding crowds of enemies I've gone for a potential field approach.
while recalculating it keeps looping through already complete elements which is obviously not what I want.
I've tried various things but I can't figure out whats going on, its likely something stupid and small but I've tried many things to prevent this, now I'm even using a dictionary to log all the completed elements and checking if a key is in the dictionary before adding it, but despite my efforts its still adding completed elements!

U, D, L, R are the elements to the Up, Down, Left and Right respectively to the element in question, its worth noting that the field loops around the map, so with a map of 32x 32 elements, element[0,0].L will be element[31,0].
EDIT: position is the elements position within the array of elements making the field.

public void start()
value = 0;
List list;
List next;
List A = new List();
List B = new List();
Dictionary done = new Dictionary();
done.Add(this.position, this);
if (U.value >= 0) A.Add(U);
if (D.value >= 0) A.Add(D);
if (L.value >= 0) A.Add(L);
if (R.value >= 0) A.Add(R);
list = A;
next = B;
int x = 1;
while (list.Count > 0)
foreach (Potential i in list)
done.Add(i.position, i);
if (!done.ContainsKey(i.U.position) && i.U.value >= 0) next.Add(i.U);
if (!done.ContainsKey(i.D.position) && i.D.value >= 0) next.Add(i.D);
if (!done.ContainsKey(i.L.position) && i.L.value >= 0) next.Add(i.L);
if (!done.ContainsKey(i.R.position) && i.R.value >= 0) next.Add(i.R);
list = (list == A ? B : A);
next = (next == A ? B : A);

any and all help would be greatly appreciated,
thanks in advanced,

BIG EDIT: I'm a complete dumbo, completely missed that elements may be added to "next" multiple times, I was stuck on this for at least 2 hours and it was one of those silly little mistakes! so sorry to waste your time with this topic. Edited by bombshell93

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!