Adding a fly animation

Next, we will make our second animation, the flying animation. With FlyingDrone selected in Hierarchy:

  1. In the Animation window, in the upper left there is a clip selected. It presently has the name of the current clip, Idle. Select it and choose Create New Clip...
  2. Name the animation Fly.

This time the animation is going to be more complicated and we're going to use the record feature in Unity.

  1. Press the red circle in the upper left of the Animation window to begin recording.

While recording, all the properties that are animated will highlight red in the editor. New keyframes will appear on the frame (red vertical timeline) you select.

This will be a simple animation and we can reduce the number of samples that it has. Let's reduce it down to 10 samples, so every 10 frames will equal one second.

  1. Enter 10 in the Samples field.

The drone will start (and end) at its origin starting position (0,0,0).

  1. Position the timeline at frame 0.
  2. Select the FlyingDrone (in Hierarchy) and make sure its Position in Inspector is (0, 0, 0).

We want the drone to fly up and reach its desired height in one second. We don't want the drone to fly too far up because we want to make sure the image continues to be tracked with the device camera.

  1. Set the red timeline at the one-second mark.
  2. In the Scene view, make sure the position gizmo is selected (showing red, green, blue axis arrows for moving the object).
  3. And move the Y position to the flying height you want.

The resulting Animation set at the one-second timeline is shown in the following screenshot:

Next, we want it to fly in a small circle. To make this easier, change the Scene view to top-down as follows:

  1. Click the Y-cone in the upper-right of the Scene window.
  2. Change the view to orthographic.

The modified Scene view should now look something like this:

Starting at the two-second mark, we will add keyframes every 20 frames, changing the drone position to the center of each edge, sequentially in a circle. Use the following steps to create the flying animation we desire:

  1. Zoom out the timeline so we can see about five additional seconds.
  2. Set the red timeline to two seconds (frame 20).
  3. Move the drone along the x axis so it's positioned at the middle of the left edge.
  4. Set the red timeline to four seconds (or type 40 in the frames field).
  5. Move the drone to the middle of the bottom edge.
  6. Set to six seconds (frame 60).
  7. Move the drone to the middle of the right edge.
  8. Set to eight seconds (frame 80).
  9. Move the drone to the middle of the top edge.
  10. Set to nine seconds (frame 90).
  11. Move the drone to the center of the card.
  12. Set to 10 seconds (frame 100).
  13. In Inspector, set the Position back to (0, 0, 0).

The Animation dopesheet now looks like this:

  1. Press the red circle Record button again to stop recording.
  2. Adjust the Scene view so it's perspective again and change the viewing angle (for example, Alt+left-mouse click).
  3. Then press the preview play button to preview the animation.

So now the drone flies in a diamond shaped pattern. We could fix this by adding more keyframes. But we will smooth it out using curves.

  1. Select the Curves view of the Animation from the bottom left of the window.

You may be familiar with curve editing from other applications. Each node point has handles to adjust the incoming and outgoing slope of the curve as it passes through that node. You can play around with the curves to make the transitions appear smoother, in each of the X and Z positions along the circle, and the Y position as the drone goes up and down.

If you need to refine a curve you can add extra keyframes by right-clicking on the curve where you want to insert a new node. For example, in the take-off Y position curve shown in the following screenshot, we added some ease-in ease-out smoothing and acceleration for good effect:

  1. To make sure the animation does not loop, navigate to the Fly animation in Project Assets, select it, and make sure Loop Time is unchecked.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.109.30