Godot Version
<Godot 4.2.2>
Hi guys,
im new to Godot and im trying to make a 2D Platformer game. Until now everything worked fine my player can walk, jump and idle he also plays the right animations for everyone of these actions. Now my problem when i press “run” while my player walks he gets faster as i intended but he is stuck on the first frame of his run animation. This frame will be there until i let go off the “run” button. I really dont understand why my run animation wont play fully i hope someone here can help me Thanks in advance
P.S. sorry for my poor english it is not my native language
Here is my Code:
extends CharacterBody2D
@onready var animated_sprite = $AnimatedSprite2D
@export var SPEED : int = 155
@export var RUN_SPEED : int = 240
@export var GRAVITY : int = 900
@export var JUMP_FORCE : int = 255
func _physics_process(delta):
var direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
if is_on_floor():
animated_sprite.play("walk")
if Input.is_action_pressed("run") and direction != 0:
animated_sprite.play("run")
velocity.x = direction * RUN_SPEED
else:
velocity.x = 0
if is_on_floor():
animated_sprite.play("idle")
# Flip Sprite
if direction == 1:
animated_sprite.flip_h = false
elif direction == -1:
animated_sprite.flip_h = true
# Gravity
if not is_on_floor():
velocity.y += GRAVITY * delta
# Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y -= JUMP_FORCE
animated_sprite.play("jump")
move_and_slide()