Godot Version
4.4.1
Question
After some help I managed to get a sprint working in my game, but after I sprint, my player seems to just stop all animations, sliding around. Video attached depicts the issue described. What is particularly peculiar about this is that it works from side to side, but not up and down.
This is what I have for my player movement code. please lmk if anymore context is needed.
extends CharacterBody2D
const sprint = 2
@export var move_speed : float = 60
@export var sprint_speed : float = 120
@export var is_sprinting = false
@export var starting_direction : Vector2 = Vector2(0, 1)
@onready var animation_tree = $AnimationTree
@onready var state_machine = animation_tree.get("parameters/playback")
func _ready():
update_animation_parameters(starting_direction)
func _physics_process(_delta):
#Get input direction.
var input_direction = Vector2(
Input.get_action_strength("right") - Input.get_action_strength("left"),
Input.get_action_strength("down") - Input.get_action_strength("up")
)
update_animation_parameters(input_direction)
# Update velocity.
velocity = input_direction * move_speed
if Input.get_action_strength("sprint"):
velocity = input_direction * sprint_speed
is_sprinting = true
else:
is_sprinting = false
# Move and Slide function uses velocity of character body to move character on map
move_and_slide()
pick_new_state()
func update_animation_parameters( move_input : Vector2):
# Dont change animation parameters if there is no move input.
if(move_input != Vector2.ZERO):
animation_tree.set("parameters/Walk/blend_position", move_input)
animation_tree.set("parameters/Idle/blend_position", move_input)
# Choose state based on what is happening with the player
func pick_new_state():
if(velocity != Vector2.ZERO):
state_machine.travel("Walk")
if is_sprinting:
state_machine.travel("Run")
else:
state_machine.travel("Idle")