How to make a variable NOT return to default every frame

i have this script:
var thrust = 0

func _process(delta: float) → void:
var thrust = thrust + Input.get_action_strength(“shift”) - Input.get_action_strength(“ctrl”)
if (thrust > 100):
thrust = 100
if (thrust < 1):
thrust = 1
apply_force(thrust * global_transform.basis.z * -100)

when i press shift it applies a force untill i let go of shift which obviously should not happen. the thrust should stay the same

It looks as though your are redeclaring the thrust variable within the _process function each time. So it is in fact not the same thrust variable you have declared outside.

I would try removing the VAR statement inside the _process function.

2 Likes

he is right use this
thrust = thrust + Input.get_action_strength(“shift”) - Input.get_action_strength(“ctrl”)
instead of this
var thrust = thrust + Input.get_action_strength(“shift”) - Input.get_action_strength(“ctrl”)