How to animate an object - Jeanmilost-Godot/Godot GitHub Wiki

Create the object animation

  1. Add a new Node3D in the scene, name it as the object name you want to animate (e.g. Door)
  2. Add another Node3D as a child of the previously created Node3D, name it Pivot (e.g. Door_Pivot)
  3. As a child of the previously created pivot, add the model you want to animate. It may be an imported model in a scene
  4. In the pivot, add an AnimationPlayer node. Make sure that the Root Node in the Inspector is set to your pivot (e.g. Door_Pivot in this case)

image

  1. Select the AnimationPlayer, click on the Animation button, and name your animation (e.g. door_opening)

image

  1. On the right of the timeline, edit the total animation time, e.g. set it to 6 (seconds) in this case

image

  1. Click on the Add Track button, select the track you want to animate, for example in this case, select 3D Rotation Track

image

  1. On the timeline, right click on the first time you want an event appears, and select Insert Key. A red point should appear

image

  1. Click on the red point and edit the frame properties in the Inspector on the right

image

  1. Repeat the points 8 to 9 until all your frames are created
  2. On the right of the track, select the interpolation mode you want to apply between the frames. You can also activate the repeat button if required

image

  1. Once created, you can play your animation with the control panel on the left

image

Add a sound to the animation

  1. Add a new track and select Audio Playback Track
  2. Right click in the timeline where the sound you want to play should start, and select Insert Key. A new yellow point should appear
  3. Click on the yellow point and drop the sound you want to play under the Stream property, in the Inspector on the right. A representation of your audio wave should replace the previously added yellow point

image

  1. You can add several sounds in the same way by repeating the points 2 to 3. You can also move the sound to another location by clicking and dragging it, shorter a sound by clicking on the right of the box and moving the size cursor, or mix 2 sounds together by selecting the transition on the right of the track

Run several animations together

You can create and run several animations together. For example you can animate a door opening while the camera is walking in the direction of the door. For that, animate the camera in the same way you animated the door (see Create the object animation above), switch to the camera, and run the both animation together by a script like this:

# Switch to the door camera and run the door animation
func RunDoorAnim():
    # show the animation camera
    $Scene/Environment/Door/Camera_Pivot/Door_Camera.current = true

    # start the door animation
    if !$Scene/Environment/Door/Door_Pivot/AnimationPlayer.is_playing():
        $Scene/Environment/Door/Door_Pivot/AnimationPlayer.play("door_opening")
	
    #start the camera animation
    if !$Scene/Environment/Door/Camera_Pivot/AnimationPlayer.is_playing():
        $Scene/Environment/Door/Camera_Pivot/AnimationPlayer.play("camera_walking")