# Make Minecraft Main Menu Camera movement

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;
// 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()
{
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;
return v;
}
}

My hierarchy setup:

any help is appreciated

• It looks like you problem is that you are not moving enough in the Y-axis. This is probably because you use the same angle value for every axis. I would try changing "float y = Mathf.Sin(angle) * depthXY;" to "float y = Mathf.Sin(angle*cameraBobCount) * depthXY;". That should make your cameras Y position change more quickly than the x and z positions. You might also have to do the same to your x position in the Update function but I'm not really sure why you need this anyway. Jan 25, 2021 at 4:19
• I wouldn't program anything for this and use the animation system instead. It's not just for characters. Jan 25, 2021 at 9:50
• @Philipp can you provide an example where an animation system can utilize this? Just so we're all in the same page Jan 27, 2021 at 14:55

Managed to fix it. The camera offset was creating problems with the math; hence, my camera is in an offset position. I modified the code so that it does what I want.

public class CameraWave : MonoBehaviour
{
[SerializeField] float speed = .1f;
// how deep and how wide the sine waves should be
[SerializeField] float depthXY = 2f;

[SerializeField] float cameraBob = 1;
// 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.y = targetLookAt.position.y;
}
void Update()
{
angle += Time.deltaTime * speed;
angle %= 360;

// make cos-sine wave
float x = Mathf.Cos(angle) * depthXY;
float y = Mathf.Sin(angle* cameraBob) * 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;
$$`$$