I want to create a Sine Wave generated from a unit circle in Unity whose amplitude and frequency can be dynamically changed by changing the speed and radius of the circle. Ex:
The result should look something like this(see pictures below) where one continuous curve shows the sustained changes in frequency and amplitude when looked over time:
This is how I'm currently approaching the problem to produce Sine wave (this script is not linked to the circle right now) but it doesn't allow for the older values to be sustained overtime..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class generateSineWave : MonoBehaviour {
[Range(0.1f,20.0f)]
public float heightScale = 5.0f;
[Range(0.1f,40.0f)]
public float detailScale = 5.0f;
public GameObject wavePlane;
private Mesh myMesh;
private Vector3[] vertices;
/*
//Unit Circle properties
public Transform target;
public float orbitDistance = 1.0f;
public float orbitDegreesPerSec = 90.0f;
public GameObject Ball;
*/
void Update()
{
GenerateWave();
}
void GenerateWave()
{
myMesh = wavePlane.GetComponent<MeshFilter>().mesh;
vertices = myMesh.vertices;
int counter = 0; //i
int yLevel = 0; //j
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
{
CalculationMethod(counter, yLevel);
counter ++;
}
yLevel ++;
}
myMesh.vertices = vertices;
myMesh.RecalculateBounds();
myMesh.RecalculateNormals();
Destroy(wavePlane.GetComponent<MeshCollider>());
MeshCollider collider = wavePlane.AddComponent<MeshCollider>();
collider.sharedMesh = null;
collider.sharedMesh = myMesh;
}
//public bool waves = false;
//public float waveSpeed = 5.0f;
void CalculationMethod(int i, int j)
{
//radius * Mathf.Sin(speed* Time.time + vertices[i].x + phase shift)
vertices[i].z = Mathf.Sin(Time.time + vertices[i].x);
vertices[i].z -=j;
}
}
I looked at the Unity Asset Store, there are a few wave generators, but none of them work with varying amplitude and frequency such that the resulting curve is one continuous curve where previous amplitudes and frequency still show in the editor.