For example, if I want to make an controlled object move on the surface of a sphere (or a cube, or whatever else) and not fall off, what should I do?

I don't need it to jump, so I don't need "sphere gravity", just to "glue" it (but if there's a simple way for sphere/cube gravity, you can tell me).


1 Answer 1


As far as I know, there is no way to specify the force of gravity per object. However, in world settings, you can set the global gravity to 0, and then you can apply whatever forces are actually required (to simulate desired gravity effects) via python.

For example, if I wanted to attract physics-enabled objects to the faces of a cube, I could do it with the following script, running on that cube:

def apply(cont):
    cube = cont.owner
    for o in cube.scene.objects:
        normal = o.rayCast(cube, o)[2]
        if not normal: continue
        g = -normal * 9.8

As you can see, I iterate over all objects in the scene, and I cast a ray from the object to the cube, in order to get the normal vector of the intersected face, which, when negated, represents the direction of the desired force I wish to apply.

After that, it's just a matter of scaling that vector, and passing it to applyForce.

Here's a .blend that shows this script in action: custom_gravity.blend


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .