Gravity Issues

Hello. I have posted below a script, that I have used before, that sets the scene’s gravity. I have version 2.63 by the way. For some reason, it doesn’t work. I have a property sensor, that, when it equals 1, activates the python controller… or at least it’s supposed to. Is there something wrong with the script, or am I just being stupid :wink: ?

import GameLogic

grav = 9.8

GameLogic.setGravity([0.0, 0.0, -grav])

i dunno but i’m guessing the error is ‘-grav’ i don’t think you can make it minus just by putting in ‘-’ before calling the variable.
maybe test
grav = -9.8
GameLogic.setGravity([0.0, 0.0, grav])
and see if that gives errors. i have a working grav script somewhere… i’ll take a look at it when i get a chance.

sorry i thought you were asking about 2.63…I misread your post sorry =P

It still didn’t work. I’m not sure what the problem is. Do you think it could be 'import GameLogic" ? Because I think someone told me before that in version 2.63, that isn’t right. I don’t know though.

so are you using 2.63?

if so use

import bge
from bge import logic
grav = -9.8
logic.setGravity([ 0.0, 0.0, grav])

It still didn’t work!!! This is frustrating. Especially because I know it worked before :slight_smile:

works for me.
increase grav to make the cube fall faster

gravity.blend (334 KB)

are you remembering the python controller and actuator

check the console for errors^^

Try this:

import bge
 
cont = bge.logic.getCurrentController()
own = cont.owner
 
own.applyForce((0, 0, -9.81), True)

Like esoneson said, check the console for errors. That way you can diagnose problems easily and really get into scripting, rather than letting every error hold you up while you wait for someone to help you.

I believe the error’s that the setGravity() function doesn’t have a captial S at the beginning, but for 2.6, you should use the 2.6 syntax / notation, which is to use the bge module as opposed to the GameLogic module. GameLogic in 2.4x = bge.logic in 2.5x+.

Your code runs perfectly fine. Just keep in mind changing gravity from default (0.0, 0.0, -9.8) to your code (0.0, 0.0, -9.8) has no visual effect ;).

Better try gravity pointing to the sky (0.0, 0.0, 9.8). The gravity is a vector! A vector has a direction.