Game Development Community

Best way to do gravity?

by Charles Randall · in Torque X 2D · 09/07/2008 (6:51 pm) · 2 replies

I'm curious what the best way to do gravity is. So far, the best solution I've found is to add a force component to simulate it, but this introduces a number of problems. First, I now have to individually manage and create gravity for every game object. Second, for customized collision routines (stick/bounce/clamp doesn't do what I want), I then have the problem of trying to sort gravity out of my physics vector in order to apply my own custom management, which is a pain as well.

Any suggestions? Alternate methods?

#1
09/08/2008 (10:17 pm)
Hmmm... Without knowing much more about your game, it's hard to suggest another solution. But one thought is to not add a force vector to everything. Instead, add something to your Game class' update method to cycle through all the objects in your TorqueObjectDatabase and apply the vertical force. Maybe even just add the force to objects that have a certain TorqueObjectType attached to it.

John K.
#2
09/09/2008 (6:16 am)
Well, it's a 2D platformer in terms of movement and such. I'd considered iterating through everything and just applying gravity, but I was simply curious if there was a better way to do this, i.e. a method provided by the engine.