Skip to content

How to create an animated model and import it in Godot

Jean-Milost Reymond edited this page Apr 10, 2024 · 7 revisions

Create the model

Several tools can be used to create a model, here Makehuman will be used, as it is free and easy to use.

Create and personalize your model. Once finished, make sure that the Game Engine skeleton is selected under the Pose/Animate tab.

image

Select Filmbox (.fbx) under Mesh Format, make sure Feet on ground and Binary FBX are selected under Options on the right. Other options may be let as default. Once ready, click on the Export button on the top right.

image

Animate the model

Open a web browser and go to Mixamo library page.

Once logged, click on the Upload Character button, and import the Filmbox model file you previously created. You can let all options by default and just follow the wizard instructions.

When your model is visible in the right view, select the animation you want to use in the left tree.

You can adjust the animation parameters in the right panel.

image

Once the animation is ready, export it by clicking the Download button on the right panel. Select FBX Binary (.fbx) as Format, With Skin as Skin, and let the other parameters by default.

image

Export one model for each animation you want your model to support.

Combine all animations together

This time Blender will be used.

Create a new scene and clear it completely. Import the first Filmbox (.fbx) animated model file.

Ensure the Layout tab is selected on the top, and on the view right, change the rendering mode: select Flat under Lighting, and Texture under Color. This way you will show the textured model.

image

Switch the timeline editor to Dope Sheet.

image

Select the Action Editor.

image

Rename your animation. It will be stored when you press the Enter key.

image

Now import the next Filmbox (.fbx) animated model file. Ensure it is selected and rename the animation. Again it will be stored after the Enter key is pressed.

image

Now you can delete the latest imported model, its animation is already stored.

Repeat the above process for each animation you want to add to the model.

Once all animations are imported, switch to the Nonlinear Animation editor.

image

Convert the animation by pressing the Push Down Action button.

image

Make sure that the first animation is selected, and in the Add menu, select the Add Action Strip item.

image

Select the next animation to import, and move it to its correct location in the timeline.

image

Repeat the process for each animation to combine.

Now select the Animation tab on the top, and under the End field on the bottom right of the view, set the end frame to the last frame of the last animation.

image

You can also play the whole animations to check if all are well combined.

Now select the File -> Export... -> glTF 2.0 (.glb/.gltf) item

image

Let the options by default and select a model file name.

image

When ready, click on the Export glTF 2.0 button on the bottom.

Import and animate the model in Godot

Import the glTF 2.0 (.glf) model file you just exported in your Godot project. Create a new scene and add a CharacterBody3D as root node. Add a child Node3D, and put your model as a child of this newly added Node3D.

Right click on the model you just added to your scene and select the Make Local item. This way the internal components of the model will be accessible, although in read-only mode.

image

Under the root node, add a new AnimationTree child, and under the Tree Root field in the inspector on the right, select New AnimationNodeStateMachine.

image

Under the Anim Player field, select the AnimationPlayer visible in the model children.

image

Select the Node3D in the tree on the left, and in the Transform fields of the inspector on the right, correct the model position and rotation, if required.

image

Now you can add and configure your animations in the tree editor.

image

image

Don't forget to add and configure the model collider, and to rename your nodes to keep a comprehensive scene. Your animated model is now ready to be used in your scenes.

image

Control the animations from a script

Below is a sample of a script allowing to control the model animation regarding the current user action.

extends CharacterBody3D

# player constants
const g_WalkingSpeed  = 1.5
const g_RotationSpeed = 4

###
# Called every frame at a fixed rate, which allows any processing that requires the physics values
#@param delta - elapsed time in seconds since the previous call
##
func _physics_process(delta):
	# rotate the player
	if Input.is_action_pressed("turn_right"):
		rotation.y -= delta * g_RotationSpeed 
	elif Input.is_action_pressed("turn_left"):
		rotation.y += delta * g_RotationSpeed

	# move the player
	if Input.is_action_pressed("move_forward"):
		var direction = $Pivot.global_transform.basis.z.normalized()

		velocity.x = direction.x * g_WalkingSpeed
		velocity.z = direction.z * g_WalkingSpeed
	else:
		velocity.x = move_toward(velocity.x, 0.0, g_WalkingSpeed)
		velocity.z = move_toward(velocity.z, 0.0, g_WalkingSpeed)

	# change the animation state depending on the user action
	$AnimationTree.set("parameters/conditions/isIdle",    velocity == Vector3.ZERO)
	$AnimationTree.set("parameters/conditions/isWalking", velocity != Vector3.ZERO)
	
	move_and_slide()

This script need to be attached to the root CharacterBody3D of the scene containing the animated model to work.