Any way to disable gravity for a physics object?

Is there any way to disable gravity for a physics object, while keeping gravity for everything else? Or, at the very least, is there any Python method I can use to get the current world gravity, so I can negate it? In most cases, I would just use a constant gravity value and negate it in the script, but I’m making a template for others to use, so it would be better to be able to find the current gravity at script execution time.

Always apply force 9.8Z :slight_smile:

Attachments

Tada.blend (408 KB)

suspendDynamics()
Suspends physics for this object.

Example: bge.logic.getCurrentScene().objects[‘Cube’].suspendDynamics()

then you can not push it, my way you can
you really did not even look @ my .blend :frowning: yet…

these with high mass = “falling platforms” aka mario yo,

:expressionless:

…I will fight you

lol
j/k

Attachments

CubeJumpMarioThrowback.blend (442 KB)

Patience, patience. I was just at my piano lesson for a half hour.:wink:

Well, I looked at your file, and it doesn’t really help with my problem. Someone might decide to change the global gravity setting to something other than 9.8. Wait, does anyone ever use a setting other than 9.8? Well, I may just have to leave it up to the user to make sure the amount of force matches the amount of gravity. Unless someone knows of a getGravity method…

@p9ablo: The issue with that method is that it disables physics completely. That means no collision detection.

force = gravity * mass

lol :slight_smile:

check out the Mario one :slight_smile: the force is 9.8*mass

so use some script to get grav then mass then set force as mass * grav?

Ah, and therein lies the problem. I don’t know how to get the gravity from a Python script.

Here you go.
http://www.blender.org/documentation/blender_python_api_2_66_release/bge.types.KX_Scene.html?highlight=gravity#bge.types.KX_Scene.gravity

Sample Script:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

gravity = scene.gravity
own.applyForce(-gravity * own.mass)

I think you need * own.mass? (is that the call?)

Yes, actually you do. I edited my post accordingly. Thanks for pointing that out.

No problem :slight_smile: I love physics!!

Thank you, that should do the trick.