Browse Source

player camera limits on Y axis

master
Joshua Reason 9 years ago
parent
commit
9cc8ee167a
4 changed files with 12 additions and 4 deletions
  1. +12
    -4
      unity_Project/Assets/Scripts/thirdPersonController.cs
  2. BIN
      unity_Project/Assets/_Scenes/MainLevel.unity
  3. BIN
      unity_Project/Assets/openingScene/CameraAnimation.anim
  4. BIN
      unity_Project/Assets/openingScene/openScene.controller

+ 12
- 4
unity_Project/Assets/Scripts/thirdPersonController.cs View File

@ -17,6 +17,8 @@ public class thirdPersonController : MonoBehaviour {
public float cameraSpeedX = 250.0f; public float cameraSpeedX = 250.0f;
public float cameraSpeedY = 120.0f; public float cameraSpeedY = 120.0f;
public float cameraDistance = 10.0f; public float cameraDistance = 10.0f;
public float maxY = 80;
public float minY = -20;
public bool active = true; public bool active = true;
public float movementSpeed; public float movementSpeed;
@ -118,6 +120,9 @@ public class thirdPersonController : MonoBehaviour {
cameraX += Input.GetAxis (CAMERA_INPUT_X) * cameraSpeedX * 0.02f; cameraX += Input.GetAxis (CAMERA_INPUT_X) * cameraSpeedX * 0.02f;
cameraY += Input.GetAxis (CAMERA_INPUT_Y) * cameraSpeedY * 0.02f; cameraY += Input.GetAxis (CAMERA_INPUT_Y) * cameraSpeedY * 0.02f;
} }
cameraY = ClampAngle (cameraY, minY, maxY);
Quaternion cameraRotation = Quaternion.Euler (cameraY, cameraX, 0.0f); Quaternion cameraRotation = Quaternion.Euler (cameraY, cameraX, 0.0f);
Vector3 cameraPosition = cameraRotation * new Vector3(0.0f, 0.0f, -cameraDistance) + cameraCentre.transform.position; Vector3 cameraPosition = cameraRotation * new Vector3(0.0f, 0.0f, -cameraDistance) + cameraCentre.transform.position;
@ -194,10 +199,13 @@ public class thirdPersonController : MonoBehaviour {
curCollider = col.collider; curCollider = col.collider;
} }
//void onCollisionExit(Collision col){
// if (curCollider == col.collider)
// curCollider = null;
//}
private static float ClampAngle (float angle, float min, float max) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
} }

BIN
unity_Project/Assets/_Scenes/MainLevel.unity View File


BIN
unity_Project/Assets/openingScene/CameraAnimation.anim View File


BIN
unity_Project/Assets/openingScene/openScene.controller View File


Loading…
Cancel
Save