How much acceleration to counter gravity?

Posted By: Hitsch

How much acceleration to counter gravity? - 11/16/08 00:03


I'm trying to creat something like an autopilot for my vehicle. It's basicly a hovercraft, that is lifted off the ground by adding a local z-velocity. Much like a helicopter. The player can normaly control that amount, to adjust the altitude. Now alternativly, that amount should be automaticly controled so that the vehicle stays at it's present altitude.
I've tried setting the z-velocity to the amount of the gravity [ph_setgravity (vector(0, 0, -500))], but thats way to much, the vehicle goes up like a rocket.
Then I tried to find an amount by slowly adding velocity, but that turned out to be harder than I thought, because it's dependent on the framerate!
Is gravity dependent on the framerate, too?
Is there a way to calculate the amount of acceleration at the moment and then use it to counter it?
After trying for a long time I got everything messed up, but maybe it's a simple task for some of you.

Thx for you Help!

so long...

Code:
phent_settype(my, PH_RIGID, PH_BOX);
phent_setmass(my, 500, PH_BOX);
phent_setfriction(my, 5);	
phent_setdamping(my, 75,100);
phent_setelasticity(my, 10, 40);

ph_setgravity (vector(0, 0, -500))

Posted By: Hitsch

Re: How much acceleration to counter gravity? - 11/21/08 22:26

Nobody...?

Can nobody show me how to calculate the current acceleration (or velocity) of an entity?
vel_x, vel_y and vel_z are only for particles as I understand.
Posted By: Vonman

Re: How much acceleration to counter gravity? - 11/22/08 07:12

If the object is at rest at the desired height, the force required to counter gravity is equal to the force of gravity itself. In other words, if the force of gravity is 500 and the DIRECTION of the force is DOWN, then the counter-force must be 500 and must be the inverse direction.

However, by countering only the gravity, you will not counter the additional downward force that comes from the downwards velocity (Z axis in this case).

I think you should code it so that there is a "target" height. If the hovercraft goes below that height, there must be an addition force in the upward direction to bring it back to the target height.
If it goes above the target height, then the "floating" force is reduced dependend on how height the hovercraft is above the target height.
If that force is taken away (or reduced), the hovercraft should fall back down again, but will go below the target once again though... you will need to add some kind of "dampener" to this process or it will bounce up and down forever.




hypothetical example:

target_height = ground_height + 10;

if(my.z < target_height)
{
float_force = target_height - my.z; // how FAR below the target height
// determins the float force

}

if(my.z > target_height)
{
float_force = my.z - target_height;
}

if(my.z == target_height)
{
float_force = -gravity; //TIMES* -1 because 500 is a negitive number
//and we want a positive version of 500
}



This is not full code, it would not work if you simply copied pasted it, but I hope you get my idea.

If this method works and you can dampen the process (so it does'nt bounce up and down forever) then it should behave like there is a repelling magnet below the hovercraft, or like it's on smooth water.
© 2024 lite-C Forums