How would I make an animation like this in Unity with a C# script?

It looks at first glance to be a lissajous pattern in threespace, with the three outputs slightly out of phase and driving the X, Y, Z euler angles of the object transform, respectively.

Here’s some code to get you thinking about it. I’m not running this, just sorta typing it, so forgive the typos. Stick this in your Update() loop on a cube and it oughta do something interesting

```
const float rate1 = 4.0f;
const float rate2 = 4.5f;
const float rate3 = 6.0f;
const float amplitude1 = 10.0f;
const float amplitude2 = 12.0f;
const float amplitude3 = 14.0f;
float t = Time.time;
transform.localRotation = Quaternion.Euler(
Mathf.Sin( t * rate1) * amplitude1,
Mathf.Sin( t * rate2) * amplitude2,
Mathf.Sin( t * rate3) * amplitude3);
```

Play with the three different rates and the amplitudes and see what you get. You might want to put it on a sub-transform so that you can do other adjustments to transforms above (or below) it in hierarchy.

1 Like

Here is the above in a more-Unity-friendly way, with public inspector variables:

```
using UnityEngine;
using System.Collections;
public class Wigglies : MonoBehaviour
{
public float rate1 = 4.0f;
public float rate2 = 4.5f;
public float rate3 = 6.0f;
public float amplitude1 = 10.0f;
public float amplitude2 = 12.0f;
public float amplitude3 = 14.0f;
void Update ()
{
float t = Time.time;
transform.localRotation = Quaternion.Euler(
Mathf.Sin( t * rate1) * amplitude1,
Mathf.Sin( t * rate2) * amplitude2,
Mathf.Sin( t * rate3) * amplitude3);
}
}
```

1 Like

Thanks man, I’ve tested it. It works like a charm.

1 Like