# gravity effecting y velocity

I got a problem with gravity effecting velocity.
my gravity works like this:

you.vl.y-=gravspeed; // the speed is for frame limting.
you.pos.y+=you.vl.y
speed*3;

Now lets say i wan’t to change the y velocity so it will throw me up to 100. I can do this but what i want is to change the gravity and still have the velocity get me to 100.
So how would i do this? I can’t figer it out.

Gravity is considered a force which affects the acceleration of an object. If you throw a rock up into the air, it causes a downward accelration (decelaration) of the object.

Not sure if you are building a flight simulator, space game, or what, but basically just about any vehicle has an acceleration rather than an automatic shift to a specific velocity. As the vehicle increases in velocity the acceleration will be reduced until the velocity reaches an equilibrium based upon current thrust, engine output or whatever.

So, you should implement acceleration (vector or scalar depending upon your need) and have gravity affect the y portion of your acceleration which affects your velocity.

Some simple algorithms:

If you are using a level for speed (20%, 50%, etc) you could implement your vehicle’s acceleration where setvel is the speed for that level of fuel or power consumption and curvel is the current velocity:

acc = ((setvel - curvel) / 2) - gravity

or

acc = ((setvel - curvel) / some_time) - gravity

You want to have (setvel - curvel) so that acceleration will drop off as speed approaches its limit for that level of fuel or power consumption. You should adjust the denominator to affect how quickly or slowly the acceleration drops off. These equations are not realistic. If you want them to be you’ll have to get into thrust and drag and lift and (one other I can’t remember)and all that good aerodynamic stuff for airplanes. Spacecraft would probably just be thrust and gravity and external forces like an explosion which could create a tumble of some sort. Lift is what helps an aircraft counteract gravity. This could also be what you are missing.

Then your velocity is basically the acceleration times the change in time. You’ll probably want to determine the time between scene rendering and use that as your time difference. Hard coding a time differential will result in different machine setups to have differing speeds.

velocity += acceleration * time_difference

You’ll have to implement it with vectors to make it work best. Best bet would be to have orientation vectors, velocity vector and acceleration vector. Orientation and velocity vectors are typically the same (parallel to direction of travel)unless you are using realistic physics. Acceleration vectors are rarely the same. You would then use vector addition for velocity and acceleration using similar equations to those above, but different.

Anyway, hope I helped.

Good luck.