side scroller graivty
hey..does anyone know how i can add gravity to a side scroller ?...my player gets stuck in mid air..i want him to fall the the floor..i have a collided(int x,int y) function which checks for collision with the map tiles..but i dont know how to implement the gravity function ?..could someone please help me out..thanks! :) im using allegro if it matters..and i made the map using mappy..
I have just recently started looking into graphics programming, and only with DirectX, but it is however my understanding that, unless you have something that does it for you, you will have to implement some kind of a physics emulator, such as the Verlet integration system.
I am not sure on this at all, and if someone knows I'm just bull........ting, please correct me and if possible, provide as much information on the subject as possible, as I would like to learn more. Thanks ;)
I'm pretty sure you can simulate gravity by simply accelerating the players velocity towards the ground.
Acceleration is added to velocity by using:
velocity = velocity0 + acceleration * delta time
This is the way I do it, and it haven't failed me yet.
woohoo! :D thanks Wazaa..i used a different formula..but the same concept that you told me!..it worked..thanks!
Actually gravity would be:
force = computeForces() ;
gravity_acceleration += (gravity_constant) * delta_time * delta_time;
acceleration = (force / mass) + gravity_acceleration;
velocity_new = velocity_old + acceleration * delta_time;
position_new = position_old + velocity_new * delta_time;
Yeah, but gravity in a game doesn't need to be accurate. In fact the more games try to simulate realistic physics in a side scroller environment (I'm looking at you 'N') the more I realize how much I enjoyed games that just faked it.
So long as there's something that says "if player not jumping and not standing on something solid then drop them" you're on the right track. Or is psuedo-code:
if !(player jumping) && !(standing on something solid)
Make like brick