Book Image

Unity 5.x Animation Cookbook

By : Maciej Szczesnik
Book Image

Unity 5.x Animation Cookbook

By: Maciej Szczesnik

Overview of this book

This recipe-based practical guide will show you how to unleash the power of animation in Unity 5.x and make your games visually impeccable. Our primary focus is on showing you tools and techniques to animate not only humanoid biped characters, but also other elements. This includes non-humanoid character animation, game world creation, UI element animation, and other key features such as opening doors, changing lights, transitioning to different scenes, using physics, setting up ragdolls, creating destructible objects and more. While discussing these topics, the book will focus on mecanim, the Unity 3D animation tool, and how you can use it to perform all these tasks efficiently and quickly. It contains a downloadable Unity project with interactive examples for all the recipes. By the end of this book, you will be confident and self-sufficient in animating your Unity 3D games efficiently.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using math to animate an object


We can use mathematical formulas to create interesting-looking animations. We are going to use this concept to make an endless curve animation with the Mathf.Sin() and Mathf.Cos() functions.

 

Getting ready

We don't need anything special for this recipe. We are going to create it from scratch in Unity. You may also download the provided example project. Open the Chapter 10 Miscellaneous\Recipe 01 Using math to animate an object directory and load the Example.unity scene there. If you run the game, you will see the finished effect—a curve animated with the Mathf.Sin() and Mathf.Cos() functions:

Final effect—curve animated with the Mathf.Sin() and Mathf.Cos() functions

How to do it...

To use math for animating a curve, follow these steps:

  1. Create an empty game object.
  2. Add a Line Renderer component to it.
  3. Create a new material of your liking and assign it to the Line Renderer.
  4. Make sure the Use World Space option in the Line renderer component is not selected (we will use...