I created a scene with my camera parented to a player object and a few bouncing balls. I want the player to stand still (in space) unless moved by user interaction and interact by the balls when hit.

As soon as the game engine starts my player is dragged by gravity I couldn't find a property to control the influence of gravity in KX_GameObject as suggested by this outdated BA Thread.

File or testing: .blend


You can do that with logic bricks alone. So you do not need a constantly running python script.

Assuming your object has a mass of 1.0:

enter image description here

activated once with an Alyways Sensor [with deactivated True Level Triggering]


  • If you have a different mass and/or gravity, you multiply the gravity with the mass to get the counterforce: Force.z = gravity * mass
  • Ensure the counterforce is given in global coordinates ([L] must be disabled), otherwise you get a rocket.
  • Gravity is per convention a force along the global -Z axis. The counterforce must be along +Z (positive Z-coordinate)
  • Do not wonder that your floating object is moving when touched, that is normal. The only reason it would stop by itself would be air friction. This is not part of the gravity.
  • This method does not work with swimming/diving objects as the counter force would not be constant.

The gravity can be almost completly neutralized with this snippet added to a BG python controller:

sce = bge.logic.getCurrentScene()
ob = sce.objects['Player']
ob.applyForce([0, 0, 19.6]) 

Note that 'Player' is the player game object.

I have no idea why I need to apply 2 times of the gravity constant (9.8 from World/Physics/Gravity) but this way it works.

  • 2
    $\begingroup$ May be related to the mass of the object? Just a guess. By that logic, it would also make sense to adjust it according to the object's mass, so ob.applyForce([0, 0, ob.mass * 9.8]). Not sure if it's actually ob.mass, just guessing (sorry!) $\endgroup$ Apr 23 '14 at 20:49

I don't know about disabling gravity, but you can set the physics type of your player to "Character" and set the "Fall Speed Max" to 0:
enter image description here

Yout object will still be able to collide with other objects in the scene, but will not fall down because of gravity.

  • $\begingroup$ Thanks, this is useful in other cases. I wan't the to keep the push back when the character is hit by a ball. $\endgroup$
    – stacker
    Apr 20 '14 at 11:54

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.