So I am trying to rotate the parent of my camera based on the angle between my mouse and the parent of the camera. Except I am doing something wrong can someone help me out its rotating in all kinds of random directions?
Not 100 % what you’re asking for, but this should get your started…
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
void Update () {
Vector3 dir = new Vector3(Screen.width,Screen.height,0)*.5f;
dir = Input.mousePosition - dir;
float angle = Mathf.Atan2(dir.y, dir.x)* Mathf.Rad2Deg;
Camera.main.transform.eulerAngles= new Vector3(0, 0, -angle);
}
}
The input to a sin and cos function is an angle, in radians. An input that flows between 0 and 2*pi will generate a full cycle. Your inputs are growing much higher than that, which is why it appears to be jumping around. You will need to scale the input into a fraction o screen size(or half screen size), then multiply by 2Pi (or Pi).