Hello! I’m trying to make a test where when the player starts running, his speed is very slow, and the timer starts. After the timer finishes, the Player speeds up and the animation changes, but I can’t figure out how, can someone help me?
First thing, is SPEED a const or var? You have it written as a const, but you are changing its value like a var. You don’t want to use all caps generally for variables.
Also, this isn’t necessary, but I’d make a basic statemachine rather than checking which animation is playing.
enum State{IDLE,SLOW,FAST}
var curr_state : State = State.IDLE
You would then change the curr_state var whenever you change animation to idle or moving respectively. Then you could use
if curr_state == State.IDLE:
const SPEED = 100
enum State{IDLE,SLOW,FAST}
var curr_state : State = State.IDLE
func _ready():
animated_sprite.play(“Idle”)
func _physics_process(delta):
var direction = Input.get_axis(“left”, “right”)
if direction:
if curr_state == State.IDLE:
curr_state = State.SLOW
velocity.x = direction * SPEED
$Timer.start()
animated_sprite.play(“Run (SLOW)”)
elif curr_state == State.SLOW:
velocity.x = direction * SPEED
else:
velocity.x = direction * (SPEED * 3.5)
animated_sprite.play(“Run (FAST)”)
elif not curr_state == State.IDLE:
animated_sprite.play(“Idle”)
curr_state = State.IDLE
$Timer.stop()
velocity.x = move_toward(velocity.x, 0, 6)
move_and_slide()
func _on_timer_timeout():
curr_state = State.FAST
This won’t reset the timer if you change directions however.
Wasn’t able to test it (on phone), but this is at least a launching pad for you.