Advertisement

Smoothing a path into line segments of certain size

Started by April 08, 2011 12:55 AM
12 comments, last by ApochPiQ 13 years, 10 months ago
I already have pathfinding working but the path points are jagged at times.

The movement goes in discreet step sizes but it's not intended to be tile based in any way even though the underlying structure I use is.

What I have is a list of somewhat jagged steps on a 2D plane. What I need is to come up with a set points that have an exact length between them to the target. The very last point will effectively just be ignored because the movement must be in certain multiples because there is a time unit cost associated with each step (this is for a turn based game).

Not sure how to even start, really. I know that some people use hermitic curves for smoothing but I don't really want a curve but straight lines.

This is my thread. There are many threads like it, but this one is mine.

I'm not clear on the question here. You have a linear piecewise path from your pathfinding routine, right? So that should already be an optimal set of "straight lines" from the start to target points. If you're getting other results it's probably because something is wrong in your pathfind, not because it needs smoothing. Maybe you could post a drawing/screenshot of what you're seeing versus what you expect?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement

I'm not clear on the question here. You have a linear piecewise path from your pathfinding routine, right? So that should already be an optimal set of "straight lines" from the start to target points. If you're getting other results it's probably because something is wrong in your pathfind, not because it needs smoothing. Maybe you could post a drawing/screenshot of what you're seeing versus what you expect?



The lengths are variable because the distance from (0, 0) to (0, 1) is not the same as the distance from (0, 0) to (1, 1). The endpoints also don't lie on graph points, it can be anywhere, so the last and first are bound to be shorter. The distance is not fixed, either, because character speeds can differ.

So I start with list of points that are either 1.0 or 1.44 units apart, with endpoints that are not.

What I need is a list of points that are all equidistant, starting at the starting point. the endpoint can just be ignored once a point along the path is closer to N.

So it's not just smoothing (which I applied already), but I need to basically rebuild a whole new path.

An ingame pic would probably only confuse things more, but maybe I will draw a pic if it is not clear.

This is my thread. There are many threads like it, but this one is mine.

Still not following, sorry...

What does having equidistant waypoints gain you? You do realize that in a Cartesian plane the only way to guarantee that every segment is the same length is to forbid diagonals, right?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I don't see the need for computing and storing every step of the path in advance, be it "jagged" along an arbitrary grid or improved to straight lines: with normal data structures your units can follow a nice path step by step.
A reasonable pathfinding output is a sequence of points where the unit will change direction (usually to turn around the corner of an obstacle), and dually a sequence of straight segments connecting them: between the corner points the unit moves straight along the connecting line segment. The beginning and the end of the path are, of course, the first and last corner.

Every turn your unit has a certain length of available movement. If the portion of path segment between its position and the next path corner is longer than available movement, it moves straight towards it; if it is shorter, the unit reaches the corner and repeats the process with the residue movement length and the next path segment. At some point the unit finishes the last segment and rests at the destination.
Successive unit positions are equidistant along the 1D path, not in the 2D plane.

Omae Wa Mou Shindeiru

Well the paths HAVE to be in line segments of a certain length, which is not the same for each character. If my explanation before made no sense you can just work from that assumption and skip the rest of this paragraph. It's not an arbitrary decsion but an absolutely vital one for my purposes, so let's not waste time arguing about the need to do this as has happened here so many times. But the short short version is that players move in steps, possibly many steps per turn (if you've played certain games this makes sense, if not it's impossible to explain), and they have a time unit cost per step and a step size that's variable from character to character. It must be in steps, that's the game design, and lots of already working code will have to be thrown out if I change that. But the movement itself is not fixed to a grid and obviously can't be if the movements are not in the grid's size.

I did draw a picture, but there seems to be no way to attach it without uploading it somewhere else.

What I want is actually really simple, though. You can even ignore this has anything to do with pathfinding.

void adjustPath(points, stepSize, adjustedPoints);

I call something like that and it takes a sequence of points with variable distance and plots it to a path of a fixed distance. Any remainder distance at the end is just discarded.

Maybe what I need is to put make these into a hermitic curve (could not remember name of this before) and then mark off ticks along the curve? Unfortunately I don't know how to do either of those steps and am not sure if that makes sense anyway.

This is my thread. There are many threads like it, but this one is mine.

Advertisement
Assuming I understand correctly what you're wanting, I think LorenzoGatti described the solution, more or less.

Say you have N segments of arbitrary length and a constant step size. While building the new path, keep track of which segment you're on and how far along the segment you are.

With each step, you need to 'consume' a certain amount of the input path, the amount being the step size. If the amount remaining of the current segment is less than the amount left to consume, you adjust the amount left to consume and move to the next segment. At some point you end up stopping in the middle of a segment somewhere (generally speaking), or you get to the end of the input path. In the first case, you add the point where you stopped to the output path.

If that's not what you're looking for, I think an example image might help in clarifying what the requirements are.
It's not really an answer at all. Yes it make it easier to make all moves based on a grid. Yes it's easier to make simple AI for a realtime game than to make AI that looks deeply ahead to achieve complex goals.

The question is not how to do pathfinding I already have that solved. The question is how to do it without being pegged to the grid in but still retain discrete steps. This is because the GUI and the AI require calculating the exact path and its costs before commiting to the course of action. That way I can mark the exact path a unit will take when it mouses over, and the cost at the end, without being stuck with a fixed step size and without being stuck with grid based movement. It is very important the user see this information and very important for the AI.

What I described is exactly how it has to be. Taking the original path points I must somehow transform it into a series of equidistant points using the specified distance which follows the original path reasonably closely.

This is my thread. There are many threads like it, but this one is mine.


Taking the original path points I must somehow transform it into a series of equidistant points using the specified distance which follows the original path reasonably closely.

That's the question I tried to answer. If my answer didn't seem relevant, then either I must not be understanding the question, or I must not be communicating clearly. (Apologies either way.)
Is there a way to just delete this? I want to try a do over on this that doesn't mention pathfiding at all in one of the other subforums, it's just too much of a red herring.

This is my thread. There are many threads like it, but this one is mine.

This topic is closed to new replies.

Advertisement