Question by
SmokiestSpace6 · Mar 14, 2016 at 08:42 AM ·
c#third-persondiagonal
Third Person Camera Roatates Diaginal
Hello Everybody, I am trying to make a third person shooter and am trying to make the camera rotate around an object with the direction of the mouse. I used the script below however I don't even think I should for a third person shooter, but the real problem is when I start to move my mouse, the camera starts to move diagonal, so I tried to freeze the Z axis through a rigidbody although I knew it would change as the camera orbits my player/object, though it still rotated. So I was wondering if there is anyway around this or if there is another way to approach a third person shooter although I haven't found any which is why I tried this
using UnityEngine;
using System.Collections;
public class CameraScript : MonoBehaviour
{
public GameObject target = null;
public bool orbitY = false;
public int lookSpeed = 30;
void Start ()
{
}
void Update ()
{
if (Input.GetAxis("Mouse X") < 0)
{
transform.RotateAround(target.transform.position, Vector3.up, Time.deltaTime * lookSpeed);
}
if (Input.GetAxis("Mouse X") > 0)
{
transform.RotateAround(target.transform.position, Vector3.down, Time.deltaTime * lookSpeed);
}
if (Input.GetAxis("Mouse Y") < 0)
{
transform.RotateAround(target.transform.position, Vector3.right, Time.deltaTime * lookSpeed);
}
if (Input.GetAxis("Mouse Y") > 0)
{
transform.RotateAround(target.transform.position, Vector3.left, Time.deltaTime * lookSpeed);
}
}
}
Thank you all for your time :)
Comment