Animation player not working, how fix?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Onulator

I’ve been looking into this for about a week or two now, and I still have no idea what’s going wrong. Basically, I’ve set up the animation player with 3 animations to activate on certain button presses in the process function, but when opening the debugger, it doesn’t work. And yet if I set it to loop and have it start up immediately in the ready function, it works properly. No matter what I do, what tutorial I look up, anything, I can’t get it to work, even though I’m pretty sure I’m using the correct code.

Am I just missing something or what?

extends KinematicBody2D

onready var P1_Animations = $P1_Animations

var isInCombo = false

var timeTillNextInput = 0.5
var time = 0

var currentAttack = 0
var previousAttack = 0
func _ready(): #Loads on startup
    time = timeTillNextInput
func _proccess(delta): #Game checks all of this every frame
	    if(currentAttack == 0):"N-Attack1-1")
	    elif (currentAttack == 1):"N-Attack1-2")
	    isInCombo = true
	    currentAttack += 1
	    time -= delta
	    if(time < 0):
		    time = timeTillNextInput
		    isInCombo = false
		    currentAttack = 0"RESET")

    if Input.is_action_pressed("ui_right"):
:bust_in_silhouette: Reply From: Inces

You can’t force animationplayer to play in process(), because it starts animation from first frame once every process frame ! Your animationplayer works, but is frozen in frame 0. You need to design a way to activate play() once, just like ready() function is activated once

Any advice on how to do that? I’m very new to Godot and would need more experience to figure out how to do that on my own.

Onulator | 2022-04-15 17:44

:bust_in_silhouette: Reply From: Mohammad_Hosein

I think the problem is on your script attachment… looks like you attach the script to KinematicBody2D (beacause first line is extends KinematicBody2D)
so if the AnimationPlayer Node(which you name it P1_Animations) is not child node of KinematicBody2D then You can’t access to it by $P1_Animations and all of the'...') will not work.

:bust_in_silhouette: Reply From: angstyloop

This was a helpful thread