-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraController.cs
34 lines (25 loc) · 1.17 KB
/
CameraController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
Vector2 mouselook;
Vector2 smoothing;
public float sensitivity = 5.0f;
public float smoothingamt = 2.0f;
GameObject character;
// Use this for initialization
void Start () {
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update () {
var mousedirection = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
mousedirection = Vector2.Scale(mousedirection, new Vector2(sensitivity * smoothingamt, sensitivity * smoothingamt));
smoothing.x = (Mathf.Lerp(smoothing.x, mousedirection.x, 1f / smoothingamt));
smoothing.y = (Mathf.Lerp(smoothing.y, mousedirection.y, 1f / smoothingamt));
mouselook += smoothing;
mouselook.y = Mathf.Clamp(mouselook.y, -90f, 90f);
transform.localRotation = Quaternion.AngleAxis(-mouselook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouselook.x, character.transform.up);
}
}