I am trying to make my Camera follow the Sphere with Mouse Aim, it follows the ball but i think that the orientation is changing so the camera is flipping sides.
Im still quite a Noob, sorry guys.
All I would like for it so do is to follow the ball and allow me to use the mouse to control it.
Here is my code for the Camera
`public class MouseAimCamera : MonoBehaviour
{
public GameObject target;
public float rotateSpeed;
Vector3 offset;
void Start ()
{
offset = target.transform.position - transform.position;
}
void LateUpdate ()
{
float horizontal = Input.GetAxis ("Mouse X") * rotateSpeed;
target.transform.Rotate (0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler (0.0f, desiredAngle, 0.0f);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
}
}
`
↧