Make objects be (not) affected by gravity.

Hello,

I got a problem which I think can be solved 2 ways.

The problem:
I have 10 cubes, 1 cube is controlled by the player.

What I need is that when I change the gravity using:

import GameLogic as gl
import bge

def main(cont):
    
   
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    
    q = cont.sensors['q']
        
    
    if q.positive:
        print("check")                        
        gl.setGravity([0, 0, 9.81])
    elif not q.positive:
        
        gl.setGravity([0, 0, -9.81])

I need the 9 other cubes be affected by it and the cube being controlled by the player unaffected by the change (so this cube keeps the -9.81 gravity)

If you think another code is better, please do.
This was the easiest way to change gravity, the only problem is that EVERYTHING (every rigid body atleast) is affected by it.

BTW the player controlled cube is also a rigid body, because it does need the normal physics (for jumping and collision etc)

I hope my problem is clear.
Can someone please help me or point me in the right direction.

Thanks in advance,
H34DhUnT3r

Why not have a logic setup like this (SPACE to end AI gravity):

Attachments

GravityOff.blend (405 KB)

Yeah, Rubbernuke’s method works fine. If you want Python, use the object.setForce() function for each object, with the Z value set to the gravity amount upwards (positive).

The easiest way to cancel gravity for one object is to activate a motion actuator with a counter force of the current gravity.

To get an own gravity you can add your own force on top of the counter force.

Obviously the most efficient way is to add this logic to the least number of objects. In your case:
change the gravity fro all objects
add counter force + separate gravity to the player controlled cube.

I hope it helps
Monster

Thanks all

I’m going to check it out and get if I’m not able to figure it out I’ll come back, but I think I’ll manage

Thanks for the help

Greetings,
H34DhUnT3r