Speed up the character after walking for 2 seconds

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By buntudu

Hello, my goal is to make the character speed up after 2 seconds of walking, not interpolating, just a set value that it goes to and when the player stops walking the speed goes back to normal.

I am using a CharacterBody2D.
Here is the template code:

 extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += 25 #gravity * delta

	# Handle Jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction = Input.get_axis("ui_left", "ui_right")
	if direction:
		velocity.x = direction * SPEED
		velocity.x = move_toward(velocity.x, 0, SPEED)

:bust_in_silhouette: Reply From: Asthmar

For increasing time after 2 seconds:

Sound like you should try using the TImer node. Set the time to 2 seconds and use the timeout signal to run code when the 2 secs are up to speed your player up.

For setting speed back:
It depends on how you set your code up but in most cases, If your move and slide velocity is 0 then your character is not moving.

Hope that helps!