Code to change 3D animation?

Godot Version

4.3

Question

I have imported .glb file which contains all the animations, and I see in the scene, I got Armature, Skeleton, Mesh and AnimationPlayer.

But now, when I run the game, the 3D model is completely still and not playing any animation. What are the codes to change and play the animation?

What code do you have so far? Godot will not know what animation to play, you might be able to mark one of the animations as Autoplay or add a AnimationTree to a new Inherited scene to control the animations with less code.

@gertkeno None, I am completely new to this, and I am lost on how to do this.

You’ve certainly found the deep end, if you just want to check out the animation right click your glb file and select “new inherited scene” this make a scene of it that can be added to, and messed with. You can select the AnimationPlayer and play animations from the bottom panel to preview them, the Autoplay button will automatically play one animation when the game loads.

Check out this introductory game and a few animation-related doc pages

1 Like

If you are not using an Animation tree but all animations are imported and working in the editor the you can type the following code

$AnimatipnPlayer.play (“Your Animation”)

You can use an if statement to play a certain animation when a input is detected or an action has happened

2 Likes

@gertkeno I tried this and while it works, it seems that I could not set the looping from there. It will say “Can’t change loop mode on animation embedded in another scene”.

Still though, I got what I wanted from the one line provided @mr.skeletonhater

You can set the animation’s loop mode in it’s advanced importer. Double click the glb file from Godot’s filesystem to change animation settings like looping.

1 Like

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