Hi, i'm back, with an even more naive question than ever before!
I've tackled A* already, and failed miserably ( see below ).
I was wondering if there's any file somewhere with a simple plug-in-and-use pathfinding system. It doesn't need to be extremely fast, just usable. I want to be able to set up a grid of given dimensions, and send an object from point A to point B, A* style. It seems that all the easy ones are 3D node-based and are way too slow for an interpolated grid. A simple 2D that i could translate into 3D (relative to the terrain, or whatever) would do nicely. That or tell me what's wrong with the above code.
thanks!! (i send a thank-you-cookie-program to whoever solves either of my problems)
I've tackled A* already, and failed miserably ( see below ).
Graphics3D 1280, 1024, 32, 2 Const gridscale = 1 Global goalx, goaly, startx, starty Global currentx, currenty Global lf = 10000000000 startx = 300 starty = 300 currentx = startx currenty = starty goalx = 800 goaly = 600 Type goodnode Field x Field y Field open = False End Type Type badnode Field x Field y End Type Type potentialnode Field x Field y Field g Field h Field lf End Type Type hlnode Field x Field y End Type setupgrid() While Not KeyHit(1) Cls() RenderWorld() drawgrid() If KeyDown(29) Then Stop EndIf If KeyHit(57) Then updatepath() Flip() Wend End Function setupgrid() For w = 0 To GraphicsWidth()-(gridscale*100) Step gridscale*100 For h = 0 To GraphicsHeight()-(gridscale*100) Step gridscale*100 node.goodnode = New goodnode node\x = w node\y = h Next Next End Function Function drawgrid() Color 0, 0, 200 For node.goodnode = Each goodnode Rect node\x, node\y, gridscale*100, gridscale*100, 0 Next Color 0, 200, 0 For hnode.hlnode = Each hlnode Rect hnode\x, hnode\y, gridscale*100, gridscale*100, 0 Next Color 255, 255, 255 End Function ;g = 10 if vertical or horizontal ;g = 14 if diagonal ;h = 10*(abs(currentx - goalx) + abs(currenty - goaly)) Function updatepath() Repeat Cls RenderWorld() If KeyHit(29) Then Stop Text 0, 0, currentx + ", " + currenty ;find the surrounding 8 nodes and replace them with potentialnodes (closing the normal ones) For node.goodnode = Each goodnode If ((node\x = currentx - (gridscale*100)) And (node\y = currenty)) Or ((node\x = currentx) + (gridscale*100) And (node\y = currenty)) Or ((node\y = currenty - (gridscale*100)) And (node\x = currentx)) Or ((node\y = currenty + (gridscale*100)) And (node\x = currentx)) Then pnode.potentialnode = New potentialnode pnode\x = node\x pnode\y = node\y pnode\g = 10 node\open = False EndIf If ((node\x = currentx + (gridscale*100)) And (node\y = currenty + (gridscale*100))) Or ((node\x = currentx + (gridscale*100)) And (node\y = currenty - (gridscale*100))) Or ((node\x = currentx - (gridscale*100)) And (node\y = currenty + (gridscale*100))) Or ((node\x = currentx - (gridscale*100)) And (node\y = currenty - (gridscale*100))) Then pnode.potentialnode = New potentialnode pnode\x = node\x pnode\y = node\y pnode\g = 14 node\open = False EndIf Next ;determine h, f (g was found above), and lf(lowest f) For pnode.potentialnode = Each potentialnode pnode\h = 10 * (Abs(currentx - goalx) + Abs(currenty - goaly)) If pnode\h + pnode\g < lf Then lf = pnode\h + pnode\g pnode\lf = True EndIf n = n + 1 Next Text 0, 20, n n=0 ;delete all potentialnodes, open up the closed nodes, and set currentx and y to the location of the lowest f For node.goodnode = Each goodnode If ((node\x = currentx - (gridscale*100)) And (node\y = currenty)) Or ((node\x = currentx) + (gridscale*100) And (node\y = currenty)) Or ((node\y = currenty - (gridscale*100)) And (node\x = currentx)) Or ((node\y = currenty + (gridscale*100)) And (node\x = currentx)) Then node\open = True Next For pnode.potentialnode = Each potentialnode If pnode\lf = True Then currentx = pnode\x currenty = pnode\y lf = 10000000 hnode.hlnode = New hlnode hnode\x = pnode\x hnode\y = pnode\y EndIf Delete pnode Next Until currentx = goalx And currenty = goaly Or KeyHit(1) End Function
I was wondering if there's any file somewhere with a simple plug-in-and-use pathfinding system. It doesn't need to be extremely fast, just usable. I want to be able to set up a grid of given dimensions, and send an object from point A to point B, A* style. It seems that all the easy ones are 3D node-based and are way too slow for an interpolated grid. A simple 2D that i could translate into 3D (relative to the terrain, or whatever) would do nicely. That or tell me what's wrong with the above code.
thanks!! (i send a thank-you-cookie-program to whoever solves either of my problems)