Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | randomguy |
extends KinematicBody2D
const GRAVITY = 50
const JUMP_FORCE = -1100
const SPEED = 200
const UP = Vector2.UP
var velocity = Vector2()
var facing_left = false
var facing_right = true
func _physics_process(delta):
velocity.y += GRAVITY
if Input.is_action_pressed("move_left"):
facing_left = true
facing_right = false
velocity.x = -SPEED
$AnimationPlayer.play("run_left")
elif Input.is_action_pressed("move_right"):
facing_left = false
facing_right = true
velocity.x = SPEED
$AnimationPlayer.play("run_right")
else:
velocity.x = 0
if facing_left:
$AnimationPlayer.play("idle_left")
elif facing_right:
$AnimationPlayer.play("idle_right")
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_FORCE
if facing_left:
$AnimationPlayer.play("jump_left")
elif facing_right:
$AnimationPlayer.play("jump_right")
velocity = move_and_slide(velocity, UP)
Try adding some debug print()'s after each animation play just sp you know if it’s even being called or not.
SF123 | 2022-05-05 03:10
It is being called, but the animation is not playing, it looks like it appears for only a split second and then immediately changes to running or idle animation.
randomguy | 2022-05-05 08:37