Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So this is an easy question. I need to implement gravity in my game but where I'm stuck is what variables do I need in my Entity object for the calculations and a good algorithm that I can use for gravity and collision. The main reason why I'm stuck here is not just I'm implementing this into a huge program that handles the different states, windows, buttons and plenty of other stuff but all I got it the x, y, width, and height for my Entity and every time I try and calculate collision if the object hits a wall it stops, and I have no acceleration variables as I don't know how to use a algorithm with them so I'm guessing as I go and so my whole program is a mess. To make it clear of what I need someone to help me with is can you show me an example of how I would use my x, y, height, and width and move it around, use jumping, use gravity. I never really saw any of this so if someone knows how to do this, and or you have done this is a game before which you could show me what you did that would be great. I'm new to this so even a link is good. Thanks in advance!

share|improve this question
What is the question? Are you asking us to implement game engine for you? What is "your x, y, height, width" ? What is "your Entity" ? – Ivan Kuckir Mar 29 '13 at 13:52
The x and y are the position, and the width and height is how big the object is. A entity has x, y, width, height, and is considered a in game object that represents something like a AI or the player. – LiquidFeline Mar 30 '13 at 2:17

Not an entire answer, but a good tip: Add a bit to your entity called "falling" (or, inversely, "supported") which specifies whether or not gravity applies to the object. When an object is sitting on top of a stationary object you don't need to apply gravity effects to it, and you can set and unset that bit on events and collisions.

share|improve this answer
Thanks for the tip! – LiquidFeline Mar 29 '13 at 4:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.