system
November 10, 2019, 8:57pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
lonely coder
I’m making a game with a robot as the main character. The robot has a limited amount of jumps until he needs to stand of the “charger” to reset it. Does anyone have anyone have any ideas on how I can rest the charge variable when standing on the “charger”?
elif Input.is_action_pressed("ui_up"):
if charge >= 1:
if on_ground == true:
velocity.y = JUMP_POWER
velocity.x = 0
on_ground = false
$AnimatedSprite.play("jump")
charge = charge - 20
This is the code on how I limit the jumps but I don’t know how to reset charge.
system
November 10, 2019, 9:52pm
2
Reply From:
eons
You can make a setter or a function to increase the charge, then use min
or clamp
to control the values.
The piece of code to control the value should be like this
charge += something; #charge can be > max_charge here
charge = min(charge,max_charge) #cut charge to the max value
Built-in GDScript constants, functions, and annotations. Description: A list of GDScript-specific utility functions and annotations accessible from any script. For the list of the global functions ...
Clamp can be used to control min and max values.
Built-in GDScript constants, functions, and annotations. Description: A list of GDScript-specific utility functions and annotations accessible from any script. For the list of the global functions ...