- Edited
Am I doing something wrong? I've done acceleration correct before, but I lost that code. For some reason my character is moving very slowly instead of gradually moving toward a higher speed.
My code:
Variables
@export var acceleration = 5.0
@export var speed = 0 # default
@export var speed_move = 100 # speed when moving with input
@export var speed_max = 999 # maximum speed
Move State:
States.MOVE:
if velocity.is_zero_approx() and ! Input.is_action_pressed("move"):
state = States.IDLE # change state
elif Input.is_action_pressed("space_bar"):
state = States.CHARGE # change state
else: # run move code
velocity = direction_input * speed # move
speed = speed_move # set speed to move speed
move_and_slide()
apply_acceleration()
acceleration function:
func apply_acceleration():
speed = move_toward(speed, speed_max, acceleration)