Jump to content
  • Advertisement
Sign in to follow this  
Maverick_24

How to achieve smooth deceleration until maximum altitude is reached

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 velocity

float decelTime = (0 - intialV) / -D; //time necessary to decelerate
float 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;


This link might be helpful: http://en.wikipedia.org/wiki/Equations_of_motion

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!