P

[Answered] Cannot Make Boost Turn off

Prydri

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. 

  • godoterfr replied

    Won't you miss the callback function of the timer?


    func _on_Timer_timeout() -> void:
    max_speed = normal_speed
  • Nathan Lovato replied

    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.

  • P
    Prydri replied

    I missed that part. Unfortunately, even after having added that line of code at the end the ship isn't turning off the boost afterwards.

  • Nathan Lovato replied

    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.