Godot Version
4.4.1
Question
I’m brand new to coding, and in my 2D Platformer I have a dash animation, but it only plays the first frame of it the whole time one holds the dash key and moves left or right. I want it to play the whole animation. Idk if this is an animation player or a coding problem, but it appears and plays normal in the animation player.
Here is the code for the player character and initializing the animations:
(((Tool-less refers to the character’s actions without any tools equipped)))
extends CharacterBody2D
@onready var animation = $AnimationPlayer
@onready var sprite = $Sprite2D
@export var jog_speed: float = 100.0
@export var dash_speed: float = 300.0
@export var jump_velocity: float = -400.0
@export var jump_time: float = 0.25
@export var gravity_force: float = 3.0
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
var is_jumping : bool = false
var jump_timer : float = 0
var is_dashing = false
func _physics_process(delta: float) → void:
if Input.is_action_pressed(“Jog Left”):
sprite.scale.x = abs(sprite.scale.x) * -1
if Input.is_action_pressed(“Jog Right”):
sprite.scale.x = abs(sprite.scale.x)
# Add the gravity.
if not is_on_floor() and not is_jumping:
velocity.y += gravity * gravity_force * delta
# Handle jump.
if Input.is_action_just_pressed("Jump") and is_on_floor():
velocity.y = jump_velocity
is_jumping = true
elif Input.is_action_just_pressed("Jump") and is_jumping:
velocity.y = jump_velocity
if is_jumping and Input.is_action_pressed("Jump") and jump_timer < jump_time:
jump_timer += delta
else:
is_jumping = false
jump_timer = 0
# 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("Jog Left", "Jog Right")
if direction:
velocity.x = direction * jog_speed
else:
velocity.x = move_toward(velocity.x, 0, jog_speed)
if Input.is_action_pressed("Run"):
if direction:
velocity.x = direction * dash_speed
else:
velocity.x = move_toward(velocity.x, 0, dash_speed)
update_animation()
move_and_slide()
func update_animation():
if velocity.x != 0:
animation.play(“Jog - Tool-less”)
else:
animation.play(“Idle - Tool-less”)
if Input.is_action_pressed("Run") and velocity.x < 0:
animation.play("Dash - Tool-less")
if Input.is_action_pressed("Run") and velocity.x > 0:
animation.play("Dash - Tool-less")
if velocity.y < 0:
animation.play("Jump - Tool-less")