# 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.

## 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); i.recalc(x); if (!done.ContainsKey(i.U.position) &amp;&amp; i.U.value >= 0) next.Add(i.U); if (!done.ContainsKey(i.D.position) &amp;&amp; i.D.value >= 0) next.Add(i.D); if (!done.ContainsKey(i.L.position) &amp;&amp; i.L.value >= 0) next.Add(i.L); if (!done.ContainsKey(i.R.position) &amp;&amp; i.R.value >= 0) next.Add(i.R); } list.Clear(); list = (list == A ? B : A); next = (next == A ? B : A); x++; } }

any and all help would be greatly appreciated,
Bombshell

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634133
• Total Posts
3015747
×