Advertisement

Units, Velocity and Waypoints

Started by July 08, 2000 08:27 PM
12 comments, last by Wayfarer 24 years, 4 months ago
I have several units that I would like to follow a list of waypoints. Their movement is based on time and each has its own velocity. What I am currently doing to see if they reached a particular waypoint is to check if they are within a certain distance of it. If so, they can advance to the next one. However, this seems like a hack because they don''t have to perfectly reach it. I was wondering what other people do in situations like this. And how would you handle it if you wanted your unit to perfectly pass through every waypoint on your list, no matter how close they are to one another (e.g. 1 pixel apart), and no matter how fast the unit is moving? Or would you even try to reach it perfectly in the first place? Wayfarer
It depends on what your exact goal is of course, but going for a prefect match (distance = zero) would make the game unbalanced I guess. What if a unit comes to a stop on the waypoint. That would prohibit all others from reaching that point. So, I would go with a circle as waypoint. Once they reach a certain distance to the waypoint they have passed it. The trick is to make it big enough to avoid what I described above and small enough to make sure they actually follow the path laid out by the waypoints and not some sort of approximative curve around them.


******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************
******************************StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...******************************
Advertisement
Hmmmm...I should call them waycircles instead

I guess I am having a hard time deciding whether I want to allow the player
to be able to change the speed of the game. I control the speed of the game
by changing the unit's velocity and I am worried that if someone increases
the game speed, the unit will overstep or get stuck on a waypoint.


Wayfarer

Edited by - Wayfarer on July 9, 2000 5:25:54 PM
If you''re worried about overshooting a waypoint because the velocity is so much greater than the distance from the waypoint that it doesn''t ever touch the waypoint, then I would suggest you simply trace along a line (even a rough line will do) between the unit and the waypoint, and check the line to see if it crosses the waypoint (i.e. check if the unit touches the waypoint at all as it travels along that line).

Alternately, you could use the "waycircles" and simply make the waycircles slightly larger at higher speeds, so that a unit couldn''t move fast enough to skip one entirely.

+------------------------------------------------
| Thp :: Threep2742@worldnet.att.net
| "Nature uses only the longest threads to
| weave her patterns, so each small piece
| of her fabric reveals the organization of
| the entire tapestry." -- Richard P. Feynman

+------------------------------------------------| Thp :: Threep2742@worldnet.att.net| "Nature uses only the longest threads to| weave her patterns, so each small piece| of her fabric reveals the organization of| the entire tapestry." -- Richard P. Feynman
The one thing I really despise is when an unit skips a waypoint by some amount
without advancing to the next one, then changes direction and skips it again
by the same amount, etc.. and gets forever stuck in this bouncing ball loop.

I am not sure how your first suggestion works, since I think you need three
points, and given the unit''s position and its waypoint, that''s only two points.

But at the moment, I am using your second suggestion about making the waycircles
larger. I have it so the distance checked is not a constant value, but a
function of the unit''s velocity and game speed. It works ok at lower game
speeds, but eventually there is a limit where large distances causes the unit
to not follow the path closely anymore.


Wayfarer
Simple idea Wayfarer, write a function that returns a radius which is a function of the agents speed, if the agent is within that radius of the waypoint then consider it has reached it''s target and should go to the next waypoint.

i.e. the radius returned should be the distance the agent can travel in one frame due to it''s speed. So if it''s travelling at 60 metres per second and the game''s running at 30 frames per second that gives you a speed of 2 metres per frame. If the distance between the way point and the agent is 2 metres or less then it''s reached it''s destination.
Also add on any potential deviation from the waypoint, such as if the agent is allowed to travel within 1 metre left and right from the centre line between waypoints add that one metre to the function.

Mike
Advertisement
Exactly. But what I was trying to point out is that when the unit moves
in larger steps (i.e. more pixels per second) it doesn't follow the path
closely anymore. I want to increase the speed without losing the precision,
but it seems like this is the best that will do.

But then again, that's not exactly true, since if I had waypoints evenly
spaced apart according to how fast an unit moves, then they would follow
the path exactly. But the waypoints I use can be placed anywhere and
are generally in close proximity to one another.

Wayfarer

Edited by - Wayfarer on July 13, 2000 3:56:10 PM
you could have a set size for your "waycircles" that gives you your desired accuracy, and just have your units slow down as they approach the waypoint, like they would anyway.

If all these errors are so fatal, why am I still alive?
If all these errors are so fatal, why am I still alive?
Actually, the thought that just occurred to me was that in order for
the unit to follow the path exactly at any speed, I would have to
analyze the path beforehand, and recalculate new waypoints for the unit
to follow based on their velocity. A faster unit would have less waypoints
to follow than a slower unit on the same path. Sound interesting?


Wayfarer
Isn''t that what I said? Where did my message go?!?! Did anyone see it?

btw, how are you calculating the distance? Using d = sqrt(x^2+y^2)?


..-=gLaDiAtOr=-..

This topic is closed to new replies.

Advertisement