Godot Version
Godot 4
Question
Hi I wanted to make an object’s gravity augment progressively to make it fall faster as time goes on
I tried
extends Node2D
var current_gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
pass
func _process(delta: float) -> void:
current_gravity += 10
but every instance of the item when created falls at the same speed
KingGD
January 5, 2025, 2:04pm
2
Try this:
extends Node2D
var current_gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
pass
func _process(delta: float) -> void:
current_gravity += 10 * delta
You just needed to multiply the 10 by delta.
wchc
January 5, 2025, 2:11pm
3
Multiplying by delta
as suggested by @KingGD is a good idea.
But you are still only changing the value of the current_gravity
variable. You need to set that value back to the physics engine to have any effect.
extends Node2D
var current_gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _process(delta: float) -> void:
current_gravity += 10 * delta
ProjectSettings.set_setting("physics/2d/default_gravity", current_gravity)
1 Like