- Home /
Question by
zacharygough07 · Apr 26 at 05:36 PM ·
rotationcamera rotateeuleranglessine-wave
How to rotate camera on sine wave.
I tried to rotate my camera based off of Mathf.Sin(Time.time)
, but it just didn't work. My script is here:
public Transform head;
public float amplitude = 5f;
public float multiplier = 5f;
public float rotAmplitude = 5f;
public float rotMultiplier = 5f;
public Vector3 originalHeadPos;
public Vector3 originalHeadRot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float headDeltaY = Mathf.Sin(Time.time * amplitude) / multiplier;
float headDeltaX = Mathf.Sin(Time.time * (amplitude/2)) / multiplier;
float headRot = Mathf.Sin(Time.time * rotAmplitude) * rotMultiplier;
//head.localPosition = new Vector3(originalHeadPos.x + headDeltaX, originalHeadPos.y + headDeltaY, originalHeadPos.z);
head.transform.eulerAngles = new Vector3(head.localRotation.x, headRot, headRot);
}
When I attach this to my camera and run the game, it does wiggle a little bit, but it wiggles in... waves? It rotates properly for a second, and then it rotates real slow. Then it rotates faster again. Can anybody help me?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613055845im_/https://answers.unity.com/themes/thub/images/avi.jpg)