Archived

This topic is now archived and is closed to further replies.

Ziyx

Speed considerations

Recommended Posts

Ziyx    122
Hi, i have coding a path for my unit to move over a terrain made up of triangles. The path is 2D and a single path is made up of an arc, then a line then another arc. The 2D path will be used to locate the unit''s position in the horizontal plane and the height of the unit''s position will be obtained from the terrain. I need to move the unit to an end point and reach the end point at a stated speed and heading. The slope of the terrain has to be accounted for, plus the maximum speeds and maximum acceleration the unit can have. I''m okay with reaching the correct heading but i''m not sure how to reach the end point at the correct speed. I''m thinking of checking the unit''s speed every frame and increase it if it''s still not max and as the unit reaches a certain distance away from the end point, it will start to decelerate. However, i think there is a chance that the unit will not be able to decelerate in time due to variations in the terrain and due to the fact that it shouldn''t have accelerated to the max speed in the first place. So, any ideas how to make the unit smart enough to reach the end point at the correct speed?

Share this post


Link to post
Share on other sites
Timkin    864
Why not apply a simply control algorithm to attempt to keep the speed of the vehicle constant.

You''re path is segmented according to terrain polygons so you have the information you need in the terrain data. Use the surface normal vector to determine the component of gravity acting to accelerate or decelerate the unit. If gravity is acting to slow the unti then set acceleration according to:

unit accel = min{unit max acceleration, -1*gravity deceleration component}

otherwise, if gravity is accelerating the unit, set unit acceleration according to

unit accel = max{unit max deceleration, -1*gravity acceleration component}

Note that these values are signed, not absolute.

If the unit enters a new terrain region at a speed less than the desired speed, then it should accelerate or decelerate accordingly, until it achieves that speed.

Just my two thoughts worth.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
Ziyx    122
:> Actually, i''m not trying to make the unit move at a constant speed throughout the path. The unit is required to accelerate and decelerate accordingly in order to reach the final destination at a stated speed. If the path was not affected by terrain(i.e flat), the points to start and stop accelerating can be calculated. But now the problem is that in 3D, the unit does not know when to accelerate and deccelerate. This is because the slope is affecting the maximum acceleration and maximum speed of the unit at each polygon. Guess this is a case where the unit have knowledge of the geometry of the path but not sufficient information to plan its speed profile over the path.

Share this post


Link to post
Share on other sites
MartinJ    122
You say that the path has already been determined and you want to control the velocity at the end of the path. I assume that you know the velocity at the beginning.

There are situations where your goal is impossible. An example is a sharp incline over the entire path and your unit cannot get to velocity in time (assume max accel=1 m/s/s over this path, init vel=0, final vel=500 m/s, total path distance=10m).

One approach that could help out is to work backwards, remembering the range of acceptable velocities at each critical point (like peaks and valleys). At the final destination, you know what your final answer needs to be. You can find out what range you need to be between at the last critical point in the path before that in order to achieve your goal. The problem is that the range can generate numbers that are nonsense like the fastest you can go is backwards (at the top of this hill, you must be in reverse or you''ll be going too fast at the bottom), or the minimum velocity is greater than the real-life maximum (in order to make it up this cliff, I must start at warp 11).

You can work backwards like this until the last thing left is to check from the first critical point back to your starting point. If your initial velocity is within the range of acceptable velocities, you can achieve your final goal. You''ve also built up a set of requirements for each piece of your path that can be used to determine if your unit should speed up or slow down to meet the next immediate goal. Depending on how many critical points you have in your path, you could end up with a recursive nightmare.

I don''t know if this has made any sense, or not. It''s kinda late for me, after working for 19 hours. I do remember a problem similar to this that I had in CSC. It was to find the path with the least cost through a directed network where each edge had an associated cost for taking it. The trick was to build up the cost backwards and at each point where there was a choice forwards to always take the smaller.

Share this post


Link to post
Share on other sites
Timkin    864
quote:
Original post by Ziyx
:> Actually, i'm not trying to make the unit move at a constant speed throughout the path. The unit is required to accelerate and decelerate accordingly in order to reach the final destination at a stated speed.



Okay, I probably misunderstood your requirements. Sorry.

The answer to your problem is one of energy balance. At any point in its path, the units total energy Etot is given by Etot = Ep + Ek = Potential energy + Kinetic energy. To solve your problem you need to consider the final energy the unit will have. If the vehicle needs to alter its speed before the end point, then it will need to accelerate (in either the positive or negative sense). There will be a contribution to this acceleration due to gravity. You will need to work out over what distance you need to apply a constant (braking or driving) force to accelerate the unit since the work done on the unit is W = Force.distance (where (.) means the vector dot product) and change in kinetic energy is equal to work. I suggest you obtain a first year college level text on the physics of kinematics. May I suggest Halliday & Resnick as an excellent starting point. It has enough information for you to solve your problem.

Cheers,

Timkin

Edited by - Timkin on August 6, 2001 1:16:49 AM

Share this post


Link to post
Share on other sites
Ferretman    276
quote:
Original post by Timkin
Why not apply a simply control algorithm to attempt to keep the speed of the vehicle constant.

You''re path is segmented according to terrain polygons so you have the information you need in the terrain data. Use the surface normal vector to determine the component of gravity acting to accelerate or decelerate the unit. If gravity is acting to slow the unti then set acceleration according to:

unit accel = min{unit max acceleration, -1*gravity deceleration component}

otherwise, if gravity is accelerating the unit, set unit acceleration according to

unit accel = max{unit max deceleration, -1*gravity acceleration component}

Note that these values are signed, not absolute.

If the unit enters a new terrain region at a speed less than the desired speed, then it should accelerate or decelerate accordingly, until it achieves that speed.

Just my two thoughts worth.

Cheers,

Timkin


This would work pretty well if you store the gravity acceleraton component with each type of "slope". That way you won''t have to caculate it all the time; it''s a simple lookup. The user won''t notice the difference if it''s 5% up one frame and 7% down the next. That''s how we did it in Hummer.





Ferretman

ferretman@gameai.com
www.gameai.com

From the High Mountains of Colorado

Share this post


Link to post
Share on other sites