diff --git a/Assets/Scripts/CameraController.cs b/Assets/Scripts/CameraController.cs index dd98a01..6fba5b9 100644 --- a/Assets/Scripts/CameraController.cs +++ b/Assets/Scripts/CameraController.cs @@ -19,7 +19,7 @@ public class CameraController : MonoBehaviour } pivot.position = player.position; - pivot.parent = player.transform; + pivot.parent = null; Cursor.visible = !Cursor.visible; Cursor.lockState = CursorLockMode.Locked; @@ -27,7 +27,7 @@ public class CameraController : MonoBehaviour void LateUpdate(){ float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed; - player.Rotate(0, camX, 0); + pivot.Rotate(0, camX, 0); float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed; if (invertY){ @@ -36,6 +36,12 @@ public class CameraController : MonoBehaviour pivot.Rotate(-camY, 0, 0); } + if(Input.GetKey(KeyCode.LeftShift)) + { + player.Rotate(0, camX, 0); + pivot.Rotate(0, 0, 0); + } + if(pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180f) { pivot.rotation = Quaternion.Euler(maxViewAngle, 0, 0); @@ -47,17 +53,20 @@ public class CameraController : MonoBehaviour } float camZ = Input.GetAxisRaw("Mouse ScrollWheel"); - + float angleY = pivot.eulerAngles.y; float angleX = pivot.eulerAngles.x; - float angleY = player.eulerAngles.y; - float cameraAngle = transform.eulerAngles.y; - //if (Mathf.Abs(cameraAngle - angleY) <= 45){ Potential start for camera following similar to banjo/mario64 + /* Code to force the camera behind the player + if(Input.GetKey(KeyCode.LeftShift)) + { + angleY = player.eulerAngles.y; + angleX = player.eulerAngles.x; + } */ - Quaternion rotation = Quaternion.Euler(angleX, angleY, 0); - transform.position = player.position - (rotation * offset); + float cameraAngle = transform.eulerAngles.y; - //} + Quaternion rotation = Quaternion.Euler(angleX, angleY, 0); + transform.position = player.position - (rotation * offset); if(transform.position.y < player.position.y){ transform.position = new Vector3(transform.position.x, player.position.y - 0.5f, transform.position.z);