Thread: side scroller graivty

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    84

    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..

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    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
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    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.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    84
    woohoo! thanks Wazaa..i used a different formula..but the same concept that you told me!..it worked..thanks!

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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;
    Last edited by VirtualAce; 02-13-2009 at 07:37 PM.

  6. #6
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    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:

    Code:
    if !(player jumping) && !(standing on something solid) 
    {
      Make like brick
    }
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Side scrolling?
    By Akkernight in forum Game Programming
    Replies: 2
    Last Post: 01-31-2009, 01:37 PM
  2. OpenGL example cube is black, white, grey only
    By edwardtisdale in forum Windows Programming
    Replies: 7
    Last Post: 09-22-2007, 02:37 PM
  3. Strange side effects?
    By _Elixia_ in forum C Programming
    Replies: 4
    Last Post: 08-16-2005, 03:25 PM
  4. 2-D Side Scroller or 2-D top down
    By Stan100 in forum Game Programming
    Replies: 1
    Last Post: 11-24-2003, 07:41 PM
  5. Side scroller help
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 09-26-2003, 10:59 AM