New AnimationTree work

Godot Version

4.1.3 stable

Question

I’m new in godot and watching now tutorials. They’re understandable, but sometimes outdated, so I stuck with AnimationTree - nodes like this isn’t work properly (playing animation depending on state):

Implemented using BlendSpace2D nodes, inside nodes four directions of animation.

Idle and Run just flickering (like animation itself) and connecting any node to End freezes animation on idle state.

My animation code now, before this I coped with it using conditions, but it broke when I added attacks:

func _animation_idle():
	player_animation.set("parameters/Idle/blend_position", _player_vector())

func _animation_run():
	player_animation.set("parameters/Run/blend_position", _player_vector())

func _animation_attack():
	velocity = Vector2.ZERO
	player_animation.set("parameters/Attack/blend_position", _player_vector())

func _process(_delta):
	match _player_state():
		IDLE:
			_animation_idle()
		MOVE:
			_animation_run()
		ATTACK:
			_animation_attack()
		ROLL: 
			_animation_roll()

I would also be grateful for other useful advices. Thanks!

use blend tree instead. you could watch some tutorials or read the docs about it

If you don’t plan to use advance conditions or expressions then you need to change the transition advance mode to Enabled and use an AnimationNodeStateMachinePlayback to travel to the different states in your state machine.

Connecting the End node would mean you want to exit the tree, which I think you do not want to if you have Idle/run loop.
As to why the animation is flickering - did you put conditions for the state transitions? What does the _animation_idle() contain for example? How do you set transitioning from one state to another?

State machine:

func _player_state():
    if Input.is_action_just_pressed("roll"):
		return ROLL
	if Input.is_action_just_pressed("attack"):
		return ATTACK
	if (_player_vector() == Vector2.ZERO):
		return IDLE
	else:
		return MOVE

I refused conditions and use only travel for now:

func _animation_playback(State: StringName):
	animation_playback.travel("{State}".format({"State": State}))
	player_animation.set("parameters/{State}/blend_position".format({"State": State}), _player_vector())


func _animation_idle():
	_animation_playback("Idle")

func _animation_run():
	_animation_playback("Run")

func _animation_attack():
	_animation_playback("Attack")

It’s not looks good but at least it works, thanks to the answer above.

Now I think how to make it so that during animation state machine returns proper state. And how to remember last vector, because now idle animation always facing left (_player_vector = (0, 0)):

1 Like

Thanks for help, now I need just improve logic for proper result.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.