How do you set 3D scene gravity?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Piece_o_Ham
:warning: Old Version Published before Godot 3 was released.

I would like to set the gravity for all objects in a 3D scene. Is there a way to set the gravity for all objects in a scene without adjusting the gravity scale for each object?

Edit: I was on 2.1 when I asked this. It would still be nice if this could be done per-scene, but this is all I need right now.

:bust_in_silhouette: Reply From: M. Alkotob

Try doing something like the example here:

Physics2DServer.area_set_param(get_world_2d().get_space(), Physics2DServer.AREA_PARAM_GRAVITY_VECTOR, Vector2(0,0))

I believe you should replace Vector2(0,0) with the values you want, the first is for the x axis and the second is for the y axis.

e.g. Vector2(0,200) would cause a downward gravity of 200 on the y axis.
Vector2(0,-200) would cause objects to fall upwards.

Let me know what happens.

Source from this answer:
https://forum.godotengine.org/1290/how-to-change-global-gravity-properties-at-runtime

Thanks, but my question was regarding 3D physics. I looked at the docs and I found that the code for 3D is almost exactly the same. This works for 3D:
PhysicsServer.area_set_param(get_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY_VECTOR, Vector3(0, -1, 0)). Note that you can also adjust AREA_PARAM_GRAVITY if you just want to pass a scalar. I would suggest editing your question for anybody who reads this in the future :slight_smile:

Piece_o_Ham | 2017-03-21 05:45

:bust_in_silhouette: Reply From: eons

Go to Scene>Project settings>Physics>Default gravity and modify that value.
You can modify gravity vector there too.


M. Alkotob answer is valid to do it by code too on autoload or main scene.

You can also add areas with space override on replace to set areas with custom gravity.

Thanks. I hadn’t yet upgraded to 2.1.2. The default gravity setting wasn’t available in 2.1.

Piece_o_Ham | 2017-03-21 05:08

You can still use area space override if you want an editor friendly option, a plane shape should work fine.

eons | 2017-03-21 20:54