Changing gravity

To best simulate being able to go under a plane (water) and swimming around, how can I change gravity when the game senses my character is under the water? Or really, so that other dynamic/rigid bodies aren’t affected, how can I change the world gravity but for only my dynamic character?

Instead of changing the gravity, just add a motion actuator to your character and apply force in the upwards direction.

That sounds so much more simple haha. Thanks, I’ll try it out and will come back if I can’t do something. Do you make those Red Frost games?

Are you talking about my blendswap posts and YouTube videos? Because those I do.

The infinite planet thing in BGE where the gravity pulls you to each planet?
I don’t remember but I think that was your stuff. Either way, that was really cool.

if 'GravityItemList' not in own:
    GIL=[]
    for objects in own.scene.objects:
        if 'GravTag' in objects:
            GIL.append(objects)
    own['GravityItemList']=GIL

for items in own['GravityItemList']:
    if not items.invalid:
         for items2 in own['GravityItemList']:
             if items2 != items:
                 v2 = items.getVectTo(items2)
                 Distance = v2[0]
                 ang = v2[1]
                 items.applyForce(v2[1]*(items2.mass/(Distance*Distance)),0)


           

Untested - this solution works but gets pricy the more items are in a scene with gravity
also I did not check the math yet on gravity, but this I think* falls off with the square of the distance)

Gravity is just -9.8 m/s ^2.

Yes, I had made that. I will be making a tutorial on it sometime soon because it was suggested. And thanks.

that is a simplification for earth Nicholas

Not for gravity in space*

oh that’s a fancy formula