Jump to content

Jerky formation walking


zoot
 Share

Recommended Posts

See from 1:17 in this video:

When groups of units walking in formation is catching up to some path that has been traced for them, they move in a jerky, "turn-on-a-dime" kind of way (it's particular gross at around 1:26). What is the reason for this? Are there any options for smoothing out this motion?

Link to comment
Share on other sites

If you do, one thing we definitely want is a "snaking" behavior for the column / long distance formation. I guess other formations should have some kind of smooth "wheeling" behavior around a given point (obstacles will still cause issues, but in the open it should be smooth). Also it's worth considering the difference between how infantry can move vs. cavalry and siege units.

Link to comment
Share on other sites

I think this is the relevant piece of code:

// Face towards the target
if (!offset.IsZero())
{
entity_angle_t angle = atan2_approx(offset.X, offset.Y);
cmpPosition->TurnTo(angle);
}

In context, I interpret "target" as meaning "next waypoint on the path". If so, the call to cmpPosition->TurnTo(angle) would be what gives the abrupt, turn-on-a-dime behavior.

Probably what happens is that the pathfinder traces a completely linear path for the unit and the UnitMotion component follows it slavishly, so jerkiness arises around the 'joints' of this path.

If this is the case, I think fixing this would actually require changes to the pathfinder to have it create smoother (non-linear) paths. We can probably not just interpolate a curved path from the linear path, because an interpolated path might collide with obstructions that only the pathfinder can account for.

Edited by zoot
Link to comment
Share on other sites

If this is the case, I think fixing this would actually require changes to the pathfinder to have it create smoother (non-linear) paths. We can probably not just interpolate a curved path from the linear path, because an interpolated path might collide with obstructions that only the pathfinder can account for.

I think a different pathfinding mode could help there, but it has to be considered that there are a number of different formations and the desired motion is formation specific (down to the individual unit and type of unit). I'm not sure how well that generalizes. Can it be accomplished with the existing pathfinder, with the unit motion planned by the formation logic? Maybe the formation can generate a series of points for each unit to follow independent of obstacles and which handles changes of direction more nicely, then pass them to the pathfinder for obstacle avoidance.

Here's another problematic case I've noticed. When one unit is in pursuit of another, it has to stop constantly when it reaches its destination, which means fast units pursuing slow units look silly and are mostly ineffective. Instead the pursuit should be continuous, especially in combat, a cavalry unit should pursue and then pass "through" its enemy, without stopping and possibly with a speed burst. Not only in combat but with escort or guard behaviors. So a "follow" or "pursue" pathfinding mode would also be helpful IMO.

Link to comment
Share on other sites

I think a different pathfinding mode could help there, but it has to be considered that there are a number of different formations and the desired motion is formation specific (down to the individual unit and type of unit). I'm not sure how well that generalizes. Can it be accomplished with the existing pathfinder, with the unit motion planned by the formation logic? Maybe the formation can generate a series of points for each unit to follow independent of obstacles and which handles changes of direction more nicely, then pass them to the pathfinder for obstacle avoidance.

I can't immediately imagine how that would work. Maybe a brute-force way could be to interpolate a smooth path and just let the chips fall where they may. As far as I understand, units will have their paths recomputed if they hit anything on their way - but I don't know how well it all would look.

Here's another problematic case I've noticed. When one unit is in pursuit of another, it has to stop constantly when it reaches its destination, which means fast units pursuing slow units look silly and are mostly ineffective. Instead the pursuit should be continuous, especially in combat, a cavalry unit should pursue and then pass "through" its enemy, without stopping and possibly with a speed burst. Not only in combat but with escort or guard behaviors. So a "follow" or "pursue" pathfinding mode would also be helpful IMO.

From what limited understanding I have, it should be fairly easy to simply cap the speed of the fastest unit to the speed of the slowest unit once the former has reached the latter. If for any reason the slow unit drifts out of range again, the fast unit would reset its speed to max until reaching the slow unit again.

Edited by zoot
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...