- Home /
Question by
LocketGoma · Aug 10, 2017 at 04:08 PM ·
cameracamera rotatecamera-look
how can stop camera wrong spinning?
hi. i'm now testing to mouse tracking camera setting.
but, when camera's rotation value is over 89 or under -89, the camera is spinning like top spin : <
public float sensitivity = 0.05f;
public Camera cam;
public GameObject character;
public Vector2 targetDirection;
public Vector2 targetCharacterDirection;
private float gab = 0.5f;
void Start () {
cam = GetComponent<Camera>();
targetDirection = transform.localRotation.eulerAngles;
if (character) targetCharacterDirection = character.transform.localRotation.eulerAngles;
}
void Update () {
Vector3 vp = cam.ScreenToViewportPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, cam.nearClipPlane));
vp.x -= gab;
vp.y -= gab;
vp.x *= sensitivity;
vp.y *= sensitivity;
vp.x += gab;
vp.y += gab;
Vector3 sp = cam.ViewportToScreenPoint(vp);
Vector3 v = cam.ScreenToWorldPoint(sp);
transform.LookAt(v, Vector3.up);
it is my simple code. i already some testing as possible as i can. but still my camera is spin like top.
please help idiot noob. : <
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612132423im_/https://answers.unity.com/themes/thub/images/avi.jpg)