How to do it...

To use Hierarchy to animate an object's local rotation, follow these steps:

  1. Put your planet models into the scene.
  2. One of our planets will be the parent of our little "planetary system." Call it Planet1 (as we will refer to it in this recipe a lot).
  3. Add an empty child game object to Planet1 and name it Planet2Orbit. The Planet2Orbit game object should be placed in the center of the Planet1 game object.
  4. Parent your second planet game object (let's call it Planet2) to the Planet2Orbit game object.
  5. Set the position of the Planet2 game object to 0x, 0y, 0z to place it exactly in the same position as the Planet2Orbit (and Planet1) game object.
  6. Move your Planet2 object to the desired distance from Planet1. Use only one axis (X, Y, or Z). See the following screenshot :
  1. Add an Animator component to the root game object of our planetary system (Planet1).
  2. Open the Animation View with the Planet1 game object selected (go to Window | Animation).
  3. Create a new Animation Clip by clicking on the Create button.
  4. Make sure the record button is pressed (upper-left corner of the Animation View).
  5. Select the Planet2Orbit game object from the Hierarchy.
  1. Rotate the Planet2Orbit a bit in one axis (choose Y for instance) to create a new key frame. After you rotate it, the Rotation property of that object will be added automatically to the Animation View. Find the Rotation section, in the Transform component in the Inspector of the Planet2Orbit game object, and enter 0 in the axis you chose (Y in this example).
  2. Move the timeline in the Animation View a few seconds forward to create the second key frame.
  3. Make sure the Planet2Orbit game object is still selected and the record button is pressed.
  4. Type 360 in the rotation section in the Transform component of the Planet2Orbit game object. Remember to type it in the same axis you chose before (Y in this example). This will create the second key frame and the animation will be perfectly looped.
  5. Play the game to see the effect of an orbiting planet.
..................Content has been hidden....................

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