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!

  • \$\begingroup\$ 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" ? \$\endgroup\$ – Ivan Kuckir Mar 29 '13 at 13:52
  • \$\begingroup\$ 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. \$\endgroup\$ – 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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