Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ZoeFish |
I followed a tutorial step by step online and everything works fine, except that when my character executes a jump or fall animation, it only plays the first frame. I’m pretty sure it’s because it conflicts with the idle animation. Any help would be extremely appreciated! Here’s my code:
extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 15
const FALLSPEED = 200
const MAXSPEED = 50
const JUMPFORCE = 300
const ACCEL = 15
var motion = Vector2()
var facing_right = true
func _ready():
pass # Replace with function body.
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > FALLSPEED:
motion.y = FALLSPEED
if facing_right == true:
$Sprite.scale.x = 1
else:
$Sprite.scale.x = -1
motion.x = clamp(motion.x, -MAXSPEED,MAXSPEED)
if Input.is_action_pressed("ui_right"):
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("run")
elif Input.is_action_pressed("ui_left"):
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("run")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("idle")
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = -JUMPFORCE
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("jump")
elif motion.y > 0:
$AnimationPlayer.play("fall")
motion = move_and_slide(motion, UP)
if motion.y == 0
motion.y = 10