Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Traitors Avatar |
“All i want is, when im not pressing Q(shield) shield_health will increment all the way to 165
I just cant seem to get anything to work (it keeps going overboard), hopefully you guys would know the answer”
extends RigidBody
func _process(delta):
if Input.is_action_pressed("shield"):
print(shield_health)
show()
else:
if shield_health < 165:
shield_health = MAX_SHIELD_HEALTH
shield_health += 1
hide()
var velocity = Vector3(0,0,0)
export var shield_health = 165
export var MAX_SHIELD_HEALTH = 165
export var MIN_SHIELD_HEALTH = 10
onready var timer = get_node("Timer")
func _ready():
timer.set_wait_time(0.2)
timer.start()
func _on_Timer_timeout():
shield_health -= 0.5
I’m kind of curious if adding an else: in the else: of your if statement will work. I’ll try it when I get home and re-comment unless you try it before I do.
func _process(delta):
if Input.is_action_pressed("shield"):
print(shield_health)
show()
else:
if shield_health < MAX_SHIELD_HEALTH:
shield_health += 1
else:
shield_health = MAX_SHIELD_HEALTH
hide()
edit: changed 165 to max shield health, figured that’d work better.
Aireek | 2020-04-16 08:56
shield_health += 1
isn’t in the if statement checking if it’s below 165. Think of functions and conditional statements as ‘boxes’ of code to execute that are separated by the tab level (I’m not sure what jargon there is for the tab key).
Magso | 2020-04-16 09:27