Possibly (Timer not working correctly for upgrade)

Godot Version

Replace this line with your Godot version

Question

Hi guys, i’m currently making a test box the increases your sprint speed every time that you touch it. When you touch it “can _interact == false” and “self.visible == false”, for some reason it seems that the timer never goes off, can someone please assist me

… I tested it and it is receiving collision it upgrades once and never returns

extends Area3D


var can_interact = false

@export var interact_timer : Timer

func _ready() -> void:
	can_interact = true
	self.visible = true

func _process(_delta: float) -> void:
	if can_interact == false:
		interact_timer.start(0.6)
	elif can_interact == true:
		self.visible = true

func _on_body_entered(body: Node3D) -> void:
	if body is player and can_interact == true:
		body.base_sprint_speed += body.sprint_speed_upgrade
		print(str(body.base_sprint_speed))
		self.visible = false
		can_interact = false


func _on_timer_timeout() -> void:
	can_interact = true
	self.visible = true

You’re restarting the timer every frame.

3 Likes

As @normalized stated, you are restarting the timer over and over. I don’t think you need any logic at the process() method. Start the timer after enabling everything in the _*on_*body_entered method. I think that should be enough.