Pathing around other units using Jumper. [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pathing around other units using Jumper.

Post by Roland_Yonaba »

NemoVonFish wrote:Aha! Perfect! Thank you very much, i'm pretty sure i'm using an earlier version, so i'll get a newer one, give that a shot, and let you know how I go.
Just grab the latest stable release: 1.8.1.
User avatar
NemoVonFish
Prole
Posts: 18
Joined: Sun Feb 24, 2013 7:48 am

Re: Pathing around other units using Jumper.

Post by NemoVonFish »

I noticed that the tunneling feature doesn't work with JPS pathfinding, and your suggestion worked fine with ASTAR, what is the difference between all the pathfinders? For what i'm doing, will one work better than any of the others?

*EDIT* Looked in to it a bit harder, I think I get why A* is the best for what i'm doing, but I don't quite get the difference between that and JPS
Last edited by NemoVonFish on Sun Dec 01, 2013 9:51 am, edited 1 time in total.
User avatar
NemoVonFish
Prole
Posts: 18
Joined: Sun Feb 24, 2013 7:48 am

Re: Pathing around other units using Jumper.

Post by NemoVonFish »

Alright, best pathing system aside, I had a look at the links you gave me, did some reading, and yes, my method wasn't the best. A better way is to only block them from moving on to or through each other when they try, though my implementation is causing some rather fatal recursion problems.

Essentially, I want all of the entities to path to the PC, overlapping pathing is fine. But when one tries to move in to a space occupied by another, stop it, set the other entities as unpathable, then generate another path. If they can find one, follow that one instead, otherwise stand there and do nothing.
That's not what happens. As soon as one tries to step on another, they go AAAAAAAAAAAAAAAAAAAAAAAAAAAAHH and the stack overflows.

Two functions are causing the problem:

Code: Select all

function npcMoveTo(foo, x, y)
	-- Is the player there?
	if player.grid_x/tileSize == x and player.grid_y/tileSize == y then
		-- Attack the player.
		enemyAttackPC(foo)
		return
	end
	-- Is there a closed door at the destination?
	if mapCurrent.scenery[y][x] == 1 then
		-- If so, open it.
		entityOpenDoor(foo, x, y)
		return
	end
	-- Is there already an entity there?
	for i, v in ipairs(enemies) do
		if x*tileSize == v.grid_x and y*tileSize == v.grid_y then
			-- If so, tag every tile containing an entity as unpathable
			for i, v in ipairs(enemies) do
				mapCurrent.pathing[v.grid_y/tileSize][v.grid_x/tileSize] = 0
			end
			-- Then generate a new path
			approachPC(foo)
			mapCurrent.pathing = deepCopy(mapCurrent.terrain)
			return
		end
	end
	-- Otherwise, move closer.
	foo.grid_x = x * tileSize
	foo.grid_y = y * tileSize
	foo.energy = foo.energy - foo.moveCost
end
and

Code: Select all

function approachPC(foo)
	calculatePath(foo, player)
	if foo.path == false or foo.path == nil then -- Can the enemy path to the PC?
		-- If not, then do nothing
		foo.energy = foo.energy - foo.moveCost
	else
		-- Then take the first step
		local nextStep = foo.path[2]
		npcMoveTo(foo, nextStep.x, nextStep.y)
	end
end
I have poured over these two functions several times, found one error (that approachPC(foo) was approachPC(v) about twenty minutes ago, causing all sorts of problems), but nothing that solves the stack overflow. Can anyone see where i'm messing up in these two? Or is the problem somewhere else that's causing the stack overflow?
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pathing around other units using Jumper.

Post by Roland_Yonaba »

NemoVonFish wrote:I noticed that the tunneling feature doesn't work with JPS pathfinding...
It is known. :nyu:
Actually, it was fixed in the following commits (after 1.8.1), but the API will be extended slightly (with new methods (get/set)Tunnelling()), so you should wait for the next release to use it. Until that, you can go with Astar finder, it handles tunnelling perfectly.
NemoVonFish wrote:What is the difference between all the pathfinders? For what i'm doing, will one work better than any of the others?
*EDIT* Looked in to it a bit harder, I think I get why A* is the best for what i'm doing, but I don't quite get the difference between that and JPS
JPS is just faster than regular Astar, as it using pruning tricks to go faster. But you will get a real benefit with JPS over Astar on large grids.
You can go through this article for in-depth details on how it works.
Rickton
Party member
Posts: 128
Joined: Tue Mar 19, 2013 4:59 pm
Contact:

Re: Pathing around other units using Jumper.

Post by Rickton »

How I fixed the problem was by, at the end of every turn, recalculating the collision map, and marking each enemy space as unpathable.
Make sure you mark the player's location as pathable, though, or they won't be able to path to the player. Likewise, they won't be able to path to each other, if you want to have creatures attack or follow each other. I came up with a way around this, too, but it's not very elegant so I won't post it if you don't need it. :P

Thanks, Roland_Yonaba, first of all for making Jumper, but secondly for mentioning that the Grid keeps a reference to the collision map object. I wasn't recreating the Grid every time I tried to pathfind, but I was recreating it after every turn when the collision map changed. Now I realize I just have to change the collision map and the Grid will update automatically.
Possession - Escape from the Nether Regions, my roguelike made in LÖVE for the 2013 7-Day Roguelike Challenge
And its sequel, simply called Possession , which is available on itch.io or Steam, and whose engine I've open-sourced!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 72 guests