Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Jumper: how to retrieve nearest walkable tile on nopath returns? — Gideros Forum

Jumper: how to retrieve nearest walkable tile on nopath returns?

piepie Member
edited November 2014 in General questions
Hi, I am using this version of Jumper (https://github.com/Yonaba/Jumper/tree/node-weight) by @Roland_Y.
I'm very happy with it but I have a problem on finding the "possible paths" for my player.

What I do is get a "ring" of tiles around the player (ranged as the player movement), and then ask jumper to find me a path to every tile on the ring:

P is the Player position, 1 are the "possible end" tiles on my ring of tiles.

0,0,0,0,0,0,0,
0,1,1,1,1,1,0,
0,1,0,0,0,1,0,
0,1,0,P,0,1,0,
0,1,0,0,0,1,0,
0,1,1,1,1,1,0,
0,0,0,0,0,0,0

On every node of every path found I place a sensible area (S), for which I ask again the "moving path" on touch, so that the player can preview and confirm the movement (also on nearest tiles).

This works, because almost every tile in this version of jumper is "parsed" (this particular version adds a "weight" to every used path node to avoid overlapping, so it's going to use any available tile). This is the same "map" with the sensible areas (S). :)

0,0,0,0,0,0,0,
0,S,S,S,S,S,0,
0,S,S,S,S,S,0,
0,S,S,P,S,S,0,
0,S,S,S,S,S,0,
0,S,S,S,S,S,0,
0,0,0,0,0,0,0

However, sometimes (when any of my ring tiles happens to be on a collision - "C" in my "drawing" ) Jumper finds nopath and returns nil, so I am missing some nodes, and no sensible area is drawn - I can't let the player to move on some tiles where he should be able to move.

0,0,0,0,0,0,0,
0,S,S,S,S,S,0,
0,S,S,S,S,S,0,
0,S,S,P,S,S,0,
0,S,S,S,0,C,0,
0,S,S,S,S,S,0,
0,0,0,0,0,0,0

I think I could avoid this if I could tweak jumper to try finding the path to the "previous tile", but this is far more advanced than my knowledge.. everything written there is like a dogma to me.. :-B does anybody have a suggestion?

I think I figured out where I should tweak, but I can't get the pathfinder to run another check on a "new tile".

at line #342 of pathfinder.lua (https://github.com/Yonaba/Jumper/blob/node-weight/jumper/pathfinder.lua)
 function Pathfinder:getPath(startX, startY, endX, endY, tunnel)
		reset()
		local startNode = self.grid:getNodeAt(startX, startY)
		local endNode = self.grid:getNodeAt(endX, endY)
		assert(startNode, ('Invalid location [%d, %d]'):format(startX, startY))
		assert(endNode and self.grid:isWalkableAt(endX, endY),
		('Invalid or unreachable location [%d, %d]'):format(endX, endY))
		local _endNode = Finders[self.finder](self, startNode, endNode, toClear, tunnel)
		if _endNode then
				return traceBackPath(self, _endNode, startNode), lastPathCost
 
		else --start of my edit
--here is where I think I should "change" the endNode to a near neighbour and run again getPath(): my guess was:
 
				local function getPrevX()
						local x
						if startX>endX then 
							x = 1
						elseif startX<endX then 
							x = -1
						end
						return x
				end
 
					local function getPrevY()
						local y
						if startY>endY then 
							y = 1
						elseif startY<endY then 
							y = -1
						end
						return y
					end
 
					if startX==endX then 
						endY = endY+getPrevY()
					elseif startY==endY then 
						endX = endX+getPrevX()
					--...and so on on every possible scenario, unless someone can enlight me on a better solution...
					end
 
				self:getPath(startX, startY, endX, endY, tunnel) --this isn't working... How do I call getPath() again?
---end of my edit
		end
	lastPathCost = 0
	return nil, lastPathCost
end
Is there a smarter way to do this? :)

Thank you, any help is appreciated.

Comments

Sign In or Register to comment.