Sign in to follow this  

Hovercraft Physics

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 [url=""]this[/url] picture shows.

How would I do that?

Share this post

Link to post
Share on other sites
The term you're looking for is spring damping. (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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this