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:
- Create an empty game object.
- Add a
Line Renderer
component to it. - Create a new material of your liking and assign it to the
Line Renderer
. - Make sure the
Use
World Space
option in theLine renderer
component is not selected (we will use...