Animations based on player trigger

Godot Version
V4.4

Im a newbie in godot, i just learnt how to do basic movement. but anyway i need a key thing in my game, animations on trigger. i’ve no idea where to put my hands in, im a 3D artisti so im making my custom models and animations. but i dont know how to connect script with certain animations.

So thing im asking is, if i wanted for example let the player move freely, but if he interact with an object, for example a cup of coffe, the player will be locked in the animations of picking up drinking and put it back down, then after the animation he will be free again.

i really need to learn how to do it, but i’ve not found any video with this specific feature for godot, every bit of help its well appreciate, doesnt really matter if you know how to do it in csharp or gdscript, i just need a way to do it.

thanks and have a nice day.

I suggest learning how the AnimationPlayer node works, as this can be used to create such things.

And “locking in” depends on how you have your player object set up. Generally you’d not accept any player input during the time of the animation (call a function that does that), and once the animations is finished, you re-enable inputs for the player.

make sure to work on at least 3 different files.
you need one for the rigged model, which you export without animations, and a copy. the use that copy to make new animations.

in godot, import the model normally but in skeleton, set a BoneProfile and animation type humanoid for humanoid, and the other option if you are not using a generic humanoid, either an animal like a dog, or if you have extra bones like for the wrists.
then set rename bones to false.

make a set of animations and export them to glb too, but in the import that is above the tree, set it to AnimationLibrary. it is more practical to pack more than one animation into the single file, but you can create more libraries later with additional animations easily.
also set a bone profile and rename bones to false. you can save your first bone profile and reuse it.
it is important that the skeletons be exactly the same. which they would be if you made it.

now, click on your model, create inherited scene, and save it.
you can change the first node to be a character body.
you might need to clear inheritance, which will mean the mesh and skeleton are saved in the scene file, they won’t update if you modify the glb with the model.

then under the first node, add an AnimationPlayer.

clicking on the animation player will open a panel at the bottom.
in AnimationPlayer editor, go to Animation -> Manage animations, it will open a dialog.



click load library, select your animation file.

this is the proper way to use animations with 3D models.

you need an AnimationTree.

next to your animation player you add an AnimationTree and in this you reference your animationplayer.
the anim player holds the animations, the anim tree can manage the animations.
you can use a blend tree, which can blend 2 or more animations, and a state machine, which can play animations one after the other and under set circumstances.
you can also nest these. I recommend having a blend tree and putting a state machine inside.

The best way (and easiest) to control a state machine is through expressions:
https://godotforums.org/d/39521-this-is-how-to-use-animationtree-state-machine-transitions-with-expressions
the docs have not been update yet on this amazing feature, but they are working on it.

1 Like

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