How to trigger 2 animations?

Godot Version

4.4.1

Question

I have a 3D project with an imported blender model with 2 animations: “up”, and “rotate”. They will play independently in the AnimationPlayer. Both are set to loop.

I have set two keyboard keys “up_toggle”, and “rotate_toggle” in my project InputMap.
In my script, in have an _input() method that detects the button presses, and can make the animations play or stop one at a time via the AnimationPlayer.

But what I would like is for these animations to play added together if they happen to both be toggled on at the same time.

After some reading, I have created an AnimationTree set to AnimationModeBlendTree, with my two animations connected to the output via an Add2 node. It seems to play them added together by default, but I don’t know how to access it to toggle the animations on or off.

Can anyone tell me how to get/start/stop/ the two animations using my AnimationTree as the toggle keys are pressed, such that they add together when both are playing at the same time?

Cheers :slight_smile:

It depends on how you set it up. Can you attach a screenshot?

You need to use an AnimationTree to be able to play multiple animations at the same time from an AnimationPlayer

More information on how to control them:

1 Like

I think I figured it out now.

My main problem was I didn’t know how to access parameters in the AnimationTree. The class reference shows that it has literally no methods. But i found out that it is also somehow a dictionary, and you can can hover over its AnimationNode parameters in the inspector to get the key name. And then you can change those parameters using tree.set( name, value ).

After that I set up a chain of Animation->TimeScale->Add2 nodes in the tree in a way that allowed adding more later on, and where each could be paused/unpaused by changing the timescale from 0 to 1 in _input() code.

This was very hard to figure out, even after reading the documentation and many youtubes and stack exchanges, and it all seems like it is probably the wrong way to achieve independent control over a series of animations on the same object. But it works, and they are added together properly if both happen to be toggled on.

Yeah, that’s not the way to do it.

So on the right of your screen should be the Inspector. On the left should be your node tree. If you click on the AnimationTree in the node tree, in the inspector every animation will show up. You will also be able to see all their properties. Like this:

If you open the MoveStateMachine, you see this:

On the right, you can open the animation like the Add2 you named tilt. Hover over Add Amount and you can see the property you need. Right-click on it and select Copy Property Path.

Then you can set the value like this in your code:

@onready var animation_tree: AnimationTree = $AnimationTree

func _tilt_change(value: float) -> void:
	animation_tree.set("parameters/tilt/add_amount", value)

If you want to change it over time do something like:

func tilt_toggle(forward: bool) -> void:
	var tween = create_tween()
	tween.tween_method(_tilt_change, 1.0 - float(forward), float(forward), 0.25)

This is why I asked for the screenshot. Because while I used a Blend2 node in my example above, you used an Add2 node.

The fact that you couldn’t find any tutorials on this would be down to searching for the right thing. The whole blend tree I just showed you came from a tutorial I did a few days ago. In the past I preferred AnimationStateMachine nodes, but after that class, I’m now reconsidering how I do animations for 3D characters.

I know it’s frustrating. Godot gives us lots of tools and the documentation can’t tell us every possible way to use something. There are two pieces of advice I can give you on that:

  1. Search for tutorials on whatever you’re trying to do, but be more general. Instead of googling how to solve your particular problem, take a step back and look for tutorials on how to use features. You’ll find a lot of really good stuff. You can also pay for classes. There are often deals. Zenva has one going as a Humble Bundle right now. I highly recommend that. It’s where I got this information.
  2. When you post on here, give us as much information about your problem. Don’t just tell us the problem you’re having, but tell us what you were trying to do when you encountered the problem (because often there’s an easier way). Also, tell us all the things you have tried to fix the problem. Put in screenshots if appropriate, but if you want to show code, copy and paste it with ``` above and below the code. The more info you give us going in, the faster you’ll get an answer.
1 Like

Thanks for such a detailed response. I will work through those steps to see what it going on.

Also thanks for the general advice about figuring out Godot :slight_smile:

I’ll close this now, Cheers

1 Like

BTW, I meant to link you to this post. Zenva has like 40 classes on sale for Godot right now on Humble Bundle still. I highly recommend them.

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