Merge pull request #7 from gjcampbell777/free_rotating_camera
Free rotating camera
This commit is contained in:
@@ -19,7 +19,7 @@ public class CameraController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
pivot.position = player.position;
|
pivot.position = player.position;
|
||||||
pivot.parent = player.transform;
|
pivot.parent = null;
|
||||||
|
|
||||||
Cursor.visible = !Cursor.visible;
|
Cursor.visible = !Cursor.visible;
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
@@ -27,7 +27,7 @@ public class CameraController : MonoBehaviour
|
|||||||
|
|
||||||
void LateUpdate(){
|
void LateUpdate(){
|
||||||
float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
||||||
player.Rotate(0, camX, 0);
|
pivot.Rotate(0, camX, 0);
|
||||||
|
|
||||||
float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
||||||
if (invertY){
|
if (invertY){
|
||||||
@@ -36,6 +36,12 @@ public class CameraController : MonoBehaviour
|
|||||||
pivot.Rotate(-camY, 0, 0);
|
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)
|
if(pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180f)
|
||||||
{
|
{
|
||||||
pivot.rotation = Quaternion.Euler(maxViewAngle, 0, 0);
|
pivot.rotation = Quaternion.Euler(maxViewAngle, 0, 0);
|
||||||
@@ -47,17 +53,20 @@ public class CameraController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
float camZ = Input.GetAxisRaw("Mouse ScrollWheel");
|
float camZ = Input.GetAxisRaw("Mouse ScrollWheel");
|
||||||
|
float angleY = pivot.eulerAngles.y;
|
||||||
float angleX = pivot.eulerAngles.x;
|
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);
|
float cameraAngle = transform.eulerAngles.y;
|
||||||
transform.position = player.position - (rotation * offset);
|
|
||||||
|
|
||||||
//}
|
Quaternion rotation = Quaternion.Euler(angleX, angleY, 0);
|
||||||
|
transform.position = player.position - (rotation * offset);
|
||||||
|
|
||||||
if(transform.position.y < player.position.y){
|
if(transform.position.y < player.position.y){
|
||||||
transform.position = new Vector3(transform.position.x, player.position.y - 0.5f, transform.position.z);
|
transform.position = new Vector3(transform.position.x, player.position.y - 0.5f, transform.position.z);
|
||||||
|
|||||||
Reference in New Issue
Block a user