![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | tofu |
I need to clamp a variable that the user can increment with input therefore I have been clamping it in the process function. Wondering if that is a good idea or if there is anyway else I could do it.
this is what I have so far:
func _process(delta):
print(sail_angle)
if Input.is_action_pressed("sail_right"):
sail_angle += 0.1
if Input.is_action_pressed("sail_left"):
sail_angle += -0.1
sail_angle = clamp(sail_angle, -70, 70)
I mean I could also clamp it after the input action:
func _process(delta):
print(sail_angle)
if Input.is_action_pressed("sail_right"):
sail_angle += 0.1
sail_angle = clamp(sail_angle, -70, 70)
if Input.is_action_pressed("sail_left"):
sail_angle += -0.1
sail_angle = clamp(sail_angle, -70, 70)
but then I am repeating code
You probably want to do that in _physics_process though, otherwise your mechanics are going to be affected by drawing frame rate.
skysphr | 2021-10-26 10:28
hmm possibly, but its related to input though, how would you propose i do it?
tofu | 2021-10-26 10:41