# How to achieve smooth deceleration until maximum altitude is reached

This topic is 3246 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a helicopter game. In the game there is a maximum altitude, lets just imagine that it is 100 feet high. If the helicopter is ascending at its maximum velocity then, I want it to begin decelerating at 90 feet high and smoothly lower its speed until it ended up at 100 feet. If the helicopter was ascending at half the maximum velocity, I would want it to begin decelerating at 95 feet high and smoothly lower its speed until it ended up at 100 feet. I need some help programmatically coming up with the altitude that the helicopter would begin decelerating to reach the maximum altitude. Does anyone have any suggestions? Maybe there is a simpler way to achieve a similar effect. Thanks, any suggestions are welcome.

##### Share on other sites
You know the rate of acceleration (or deceleration) that you will use once you begin to decelerate. You can plug this into the motion equation to find out how far the helicopter will travel for a given time, given initial velocity, and constant acceleration.

Say your helicopter can decelerate vertically at the rate of D, V is the helicopters vertical velocity. MaxA is the max altitude you want to have a zero V at. StartA is the height you should start decelerating at D to reach zero V at MaxA. That's what you want right?
const float D = some decelleration rate, possibly gravity;const float intialV = helicopters vertical velocityfloat decelTime = (0 - intialV) / -D; //time necessary to deceleratefloat distTraveled = initalV * decelTime + 0.5 * D * decelTime ^2;

so now that you know how far you will travel during the deceleration time, you can subtract that from your max altitude.
float StartA = MaxA - distTraveled;

[Edited by - bzroom on December 1, 2009 3:21:45 PM]

##### Share on other sites
DECEL_ALT = 90
MAX_ALT = 100

if(helicopter.velocity.y > 0.0f) {
// if you are going upward

real_decel_alt = DECEL_ALT + ((MAX_ALT-DECEL_ALT)*(1 - helicopter.velocity.y/MAX_VELOCITY_Y));
// this would interpolate the deceleration altitude from DECEL_ALT to MAX_ALT based on the speed

if(helicopter.altitude > real_decel_alt) {
// if you are above the deceleration altitude and are going upward

helicopter.velocity.y = helicopter.velocity.y*(1 - (MAX_ALT - helicopter.altitude)/(MAX_ALT - real_decel_alt)

} // end if(helicopter.altitude > real_decel_alt)

} // end if(helicopter.velocity.y > 0.0f)

I'm 95% sure that's what you described...

EDIT: But you should use bzroom's... It is simpler and more appropriate.

##### Share on other sites
I did something similar with vehicles that were nearing their destination.

Along the lines of:
if(distance_to_destination <= 0.5*speed*speed/max_deceleration)    speed -= max_deceleration * timestep;

##### Share on other sites
Thanks all for the suggestions. After reading these replies, I think I realize what I need to do. I will do something similar to bzroom's example tonight.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009677
• ### Who's Online (See full list)

There are no registered users currently online

×