I'm having difficulties with getting boost to turn off. After adding the Timer and adjusting the wait time to 0.6 and turning the One Shot to "On" the boost still refuses to slow down once the Spacebar is released. I've double-checked my coding at this point and everything seems to be correct.
extends Sprite
var boost_speed := 1500.0
var normal_speed := 600.0
var max_speed := normal_speed
var velocity := Vector2.ZERO
func _process(delta: float) -> void:
var direction := Vector2.ZERO
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1.0:
direction = direction.normalized()
if Input.is_action_just_pressed("boost"):
max_speed = boost_speed
get_node("Timer").start()
velocity = direction * max_speed
position += velocity * delta
if direction:
rotation = velocity.angle()
I would greatly appreciate any help that could be offered.
UPDATE: Thanks to everyone for your help, my mistake was typing that portion out longhand instead of going by the instructions.
As mentioned by godoterfr, the code you shared is lacking the function we connect the Timer's timeout signal to in the lesson. Without this and the signal connection, the boost effect will not time out.
Is the Timer's timeout signal connected to the function? If it is, you should see a green icon next to the function, the one on the left below.
If it's not there, then I'd invite you to rewatch the video, because we cover how to connect it and write this function step-by-step there. You might have missed this bit.