Hi Nemo,
First of all, thanks using Jumper. I appreciate the feedback.
Now, let me highlight a few things:
First of all, when moving a team/group of units from a target to a destination, they will tend to lineup at the destination, causing a "stack".
That is totally normal, just because the path they following leads to the same destination.
I am very aware of that, though I won't pull any patch in the library code to "fix" this, mostly because it goes out of the scope of the original intent of Jumper.
But, if for some reason, you want to avoid that "stacking" problem, there is a couple of solutions.
The one you are using is not the best, and is not even suitable because it is quite costful. Indeed, there is nicer one that relies on
steering behaviours. Basically, you have a team of units which are supposed to follow a path, but you want them to move in formation....In this case, steering is definitely the way to go, in my humble opinion.
Here is Craig Reynolds'
original paper on the subject, followed with some
slides. You might also be interested in this
very straightforward tutorial series at tuts.plus. There are lots of behaviors, and they can be combined to create new ones. The one you might be interested in is crowding.
Also, I have been working myself on
Steering behaviors, and I got pretty interesting code to show, although this experiment is paused at the moment.
Second, I noticed that you are doing something wrong, with Jumper. And actually, a lot of people do the same mistake.
You are not suppose to create a grid object each time you are requesting a path. This operation is quite costful (depending on the size on your map), but it is just irrelevant, since once the grid is create, it keeps internally a reference to the original map. Therefore, if you change something on this map, the grid object will be aware of that.
Code: Select all
-- only once, unless you change the table map with another table having a different size
local grid = Grid(map)
function calculatePath(entity, target)
local sx, sy = worldToTile(entity)
local ex, ey = worldToTile(target)
local path = myFinder:getPath(sx, sy, ex, ey)
if path then
path:fill()
end
entity.path = path
end
Do not hesitate if you have further questions, or if you want to expand on this.