I intend to make exactly like this. I highly suggest you watch just 5 seconds of the video because it already explains what I intend to do. I’ve been trying cosine and sine on vector3s but I can’t seem to make it work since I usually get these results:
This however is my intended result:
This is my current code:
public class CameraWave : MonoBehaviour
{
(SerializeField) float speed = 1f;
// how deep and how wide the sine waves should be
(SerializeField) float depthXY = 2f;
// radius of the circle
(SerializeField) float radiusZ = 10f;
// makes the waves on the y axis and translates it
(SerializeField) Transform targetLookAt;
// parent of target look at so we can move it in the z direction
(SerializeField) Transform lookAtContainer;
// set angle to middle
float angle = 0.35f;
Vector3 cameraOffset;
void Start() { cameraOffset = targetLookAt.position; }
void Update()
{
// adjust angle
angle += Time.deltaTime * speed;
angle %= 360;
// make cos-sine wave
float x = Mathf.Cos(angle) * depthXY;
float y = Mathf.Sin(angle) * depthXY;
// set to look at
Vector3 position = new Vector3(x,y);
targetLookAt.localPosition = position;
// update container to make it go in circles
lookAtContainer.position = MakeCircleZ(angle) + cameraOffset;
}
Vector3 MakeCircleZ(float angle){
Vector3 v = Vector3.zero;
v.x = (radiusZ * Mathf.Cos(angle));
v.z = (radiusZ * Mathf.Sin(angle));
return v;
}
}
My hierarchy setup:
any help is appreciated