![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | WitheredApricot |
So I have most of my animations and things set up, but I cannot fix my animation from playing only the first frame. Every time I click the mouse button, it plays the first frame and holds it there until I release. I can move around during this and jump. How can I get it to play the full animation from start to finish?
extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 20
const MAXFALLSPEED = 200
const MAXSPEED = 80
const JUMPFORCE = 300
const ACCEL = 10
var motion = Vector2()
var facing_right = true
func _ready():
pass
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
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("right"):
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("Walking")
elif Input.is_action_pressed("left"):
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("Walking")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("Idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y = -JUMPFORCE
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jumping")
elif motion.y > 0:
$AnimationPlayer.play("Falling")
if Input.is_action_just_pressed("Attack1"):
$AnimationPlayer.play("Attack1")
motion = move_and_slide(motion,UP)
I had a similar issue with an aim_down_sights animation. I had walk, run, ADS, etc all in the same animation player and, when I pressed ADS, the walk anim would immediately override in the middle of ADS leaving it half played. Could this be your issue?
My solution was to put ADS in a separate animation player (although I’m sure tweening could work, but I don’t know how to use that yet). You could also create a state machine so that in the ATTACKING state, the movement animations can’t play.
BillRogers | 2023-01-20 06:06
Adding a second animation player almost works, I plays the full animation sometimes but is still really buggy. I think this is because its conflicting with my idle animation but I can try to figure this out. Its progress though! I really appreciate it!
WitheredApricot | 2023-01-20 16:12