i am pretty new to c++ and dark gdk. im trying to make a simple platform game to start off. i have the basic controls down, the animations, and collision. but i am having much trouble finding how to create the effects of gravity. please help.
Gravity should be treated as a (physics)vector. In a 2-D scenario the Gravity vector will have 2 components. X & Y.
Gravity.x = +0.0f; //Since gravity acts only in vertical direction
Gravity.y = -9.8f;
Going by Newton's equations in a non-inertial frame:
S = ut + (at^2)/2 , S :displacement, u :initial velocity, t :time
They will split into X-Y with each component contributing in displacement. And the net displacement will be:
sqrt( Sx^2 + Sy^2 ) Where Sx : is X component of Displacement & similarly for Sy.
& deviation will be tangent^-1(Sy/Sx)
Speaking in simpler terms:
ball.x += ball.velocity.x*dt + (GRAVITY.x*dt*dt)/2
ball.y += ball.velocity.y*dt + (GRAVITY.y*dt*dt)/2
/* You can either move the ball using Cartesian coordinates or polar. */