Sprite Animations Not Advancing Correctly On Keypress
Asked Answered
G

5

0

Hey all! I'm just getting started with Godot and I have a quick question about animating sprites using an animation tree. I'm trying to get my character sprite to play different movement animations based on which keys are pressed. So far I have walk and idle. I've set up all of my animations correctly in the animation player and I've created the Idle and Walk BlendSpace2D objects in the animation tree, but when I run my game, for some reason only the starting animation plays (which happens to be idle right) and no matter which key I press, the idle right animation never stops playing. So basically I'm able to move my character fluidly around the screen but the sprite animations don't change. Here's my code:

extends CharacterBody2D

@export var move_speed : float = 100
@export var starting_direction : Vector2 = Vector2(0, 1)

@onready var animation_tree = $AnimationTree

func _ready():
update_animation_parameters(starting_direction)

func physics_process(delta):
var input_direction = Vector2(
Input.get_action_strength("right") - Input.get_action_strength("left"),
Input.get_action_strength("down") - Input.get_action_strength("up")
)

update_animation_parameters(input_direction)

velocity = input_direction * move_speed
move_and_slide()

func update_animation_parameters(move_input : Vector2):
if(move_input != Vector2.ZERO):
animation_tree.set("paramters/Walk/blend_position", move_input)
animation_tree.set("paramters/Idle/blend_position", move_input)

I attached a picture of how my animation tree is setup, also.

For reference, here's a link to the video tutorial I'm using:

Any help would be greatly appreciated!

Gaff answered 8/12, 2023 at 3:25 Comment(0)
G
1
animation_tree.set("paramters/Walk/blend_position", move_input)
animation_tree.set("paramters/Idle/blend_position", move_input)

I'm noting a spelling issue with the word "parameters" in both of these two lines, see if correcting this solves your issue.

Guyon answered 8/12, 2023 at 21:46 Comment(0)
C
1

That looks like an AnimationNodeStateMachine. You're sure you're using AnimationNodeBlendSpace2D?

Counterpane answered 8/12, 2023 at 23:29 Comment(0)
G
1

Guyon That was it! I can't believe I missed that! Thank you so much!

Gaff answered 9/12, 2023 at 20:39 Comment(0)
G
0

Counterpane It is an AnimationNodeStateMachine and my transitions are BlendSpace2d types. I did end up fixing this issue though!

Gaff answered 9/12, 2023 at 20:47 Comment(0)
G
0

Gaff It happens to all of us 😅

Guyon answered 12/12, 2023 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.