Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerGuy123

Hovercraft Physics

This topic is 2145 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'm trying to implement hovercraft like physics into my game but I need help. An improtant thing to note is that the hovercraft will be pretty high off the ground unlike realistic hovercrafts. After searching and asking questions I arrived at this source code:


double g = 9.8d; //gravity
double m = 1.0d; //mass
double fMax = 15; //maximum upwards force
double idealHeight = 100; //ideal height the craft should be off the ground
double v; //velocity
void Update() {
double h = Math.Abs((craft.Y + craft.Height) - ground.Y); //determin the craft's height from the ground.
double a = (g - f(h)) * m; //acceleration
v += a; //velocity
v = MathHelper.Clamp((float)v, -15.0f, 15.0f); //make sure the acceleration doesn't get out of hand
craft.Y += (int)v; //assign the velocity
}
double f(double h) { //this function return the amount of upwards force
return Math.Max(0, h * (g - fMax) / idealHeight + fMax);
}


One cunfusing thing to note is that my game is 2D with (0, 0) being the top left corner of the window and (100, 100) being accrosed and down 100 pixels. This is why I have the Math.Abs(craft.Y + craft.Height) - ground.Y whole thing.

Now the problem:
This code works but the craft just goes up and down up and down up and down enlessly. I would like the craft's velocity to diminish over time to equal out with the idealHeight. Like this picture shows.

How would I do that?
Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The term you're looking for is spring damping.

http://en.wikipedia.org/wiki/Damping
http://www.myphysicslab.com/spring1.html (more useful, IMO)

Basically you need to apply a friction force against the oscillating spring force that you're applying to the hovercraft.

Share this post


Link to post
Share on other sites
I am working on what appears to be an very similar system and have used the same formula as you did. I was hoping you could enlighten me with what formula or code you used to achieve the required damping.

Thank you in advance for any assistance you can provide.

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!