Hovercraft Physics

Started by
2 comments, last by GeekWrath 11 years, 6 months ago
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.
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.
Ah yes thank you. Very informative links.
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.

This topic is closed to new replies.

Advertisement