How to change global gravity properties at runtime?

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

How do you change global gravity properties from code at runtime?

Thought it might be possible from a custom integrate_forces method where the physics state is passed to you, but only see get_total_gravity(); no setter there. Was hoping gravity could be accessed/changed from a normal fixed_process method.

Thought there may be a way to reference a “default” Area2D in a scene which would also allow gravity to be changed, but can’t find a way.

Is there an easy way to do this, before I kludge something together with these various options?

:bust_in_silhouette: Reply From: puppetmaster-

with this kind of code I have changed the global gravity in my game

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

Note that you can also set AREA_PARAM_GRAVITY (which is a scalar) if you just want to change the strength.

Piece_o_Ham | 2017-03-21 05:47

Underscores seem to have disappeared from this answer. I think it should be:
Physics2DServer.area_set_param(get_world_2d().space, Physics2DServer.AREA_PARAM_GRAVITY_VECTOR, Vector2.ZERO)

Aristonaut | 2020-02-25 02:23