FP2.1: Variable Gravity only affecting single object?

Topics: User Forum
Aug 3, 2010 at 4:17 PM


Just a quick question, I was wondering if its possible to have different gravity values affect different bodies/geoms?

For example, in a side-scrolling platformer game, my character is able to jump, and the jump code directly controls the body/geoms Y coordinate without input from the physicsSimulator, until it reaches the apex of its jump, then the simulator takes over and gravity brings the character back to Earth.

What I would like to do, is when the player presses jump a second time, in the air, the character starts a "glide" movement, which is effectively, gravity/2.

Problem is, I don't want the gravity to be changed for the other objects in the world. Is this possible in the simulator?

If not, I can still code in gravity to directly affect the players Y position, and set ignoreGravity to true for the player while gliding, but I thought if I could simply change the gravity variable or something, it would be much simpler and could use it to create some puzzles or interesting situations.


Aug 3, 2010 at 4:52 PM
FPE 2.1 only have a single global gravity variable. Creating gravity for single objects can be done with a gravity controller, but different gravity values is still not supported by the engine. You could code up a controller that does the job.
Aug 3, 2010 at 5:34 PM

Thankyou for the fast reply, that's all I needed to know

Aug 4, 2010 at 8:14 AM
I may be completely off base with this, but if you apply a constant force upwards that is PhysicsSimulator.Gravity/2, it should (if my thinking is correct) push against gravity and effectively half it. As long as it's not strong enough to counter-act gravity completely the character should still fall downwards.
Aug 5, 2010 at 8:33 AM
Edited Aug 5, 2010 at 8:34 AM

I'm suprised I didn't think of that! Thankyou! That should by far be the easiest way to implement it, with the least code too. Being as my own player class handles the X movement, it was only the gravity that needed changing, so it should work perfectly! (In theory)