Advertisement
Downtion

Basic Camera

Feb 26th, 2019
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class C_CameraC : MonoBehaviour
  6. {
  7. [Header("External Refernces")]
  8. public Transform T_Player;
  9. private CharacterController CC_PlayerCC;
  10.  
  11. [Header("Camera Settings")]
  12. public float F_CamTurnSpeed;
  13. public float F_CamDistance;
  14. public float F_CamTilt;
  15. public float F_CamTiltLowest;
  16. public float F_CamTiltHighest;
  17.  
  18. [Header("Stored Camera Information")]
  19. public float F_DirectionItsHeading;
  20.  
  21. [Header("Player Information")]
  22. public float F_PlayerHeight;
  23.  
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. CC_PlayerCC = T_Player.GetComponent<CharacterController>();
  28. UpdatePlayerHeight();
  29. }
  30.  
  31. void UpdatePlayerHeight()
  32. {
  33. F_PlayerHeight = T_Player.localScale.y / 2;
  34. }
  35.  
  36. // Update is called once per frame
  37. void LateUpdate()
  38. {
  39. //Camera Section (1/1)
  40. F_DirectionItsHeading += Input.GetAxis("Mouse X") * Time.deltaTime * F_CamTurnSpeed; //Stores our Mouse X information for rotating the camera later
  41. F_CamTilt += Input.GetAxis("Mouse Y") * Time.deltaTime * F_CamTurnSpeed; //Modifying the tilt
  42. F_CamTilt = Mathf.Clamp(F_CamTilt, F_CamTiltLowest, F_CamTiltHighest); //limited camera rotation on Y Axis
  43. transform.rotation = Quaternion.Euler(F_CamTilt, F_DirectionItsHeading, 0); //Camera tilt setup
  44.  
  45. transform.position = T_Player.position - transform.forward * F_CamDistance + Vector3.up * F_PlayerHeight; //Set a Camera distance away from the player & sets the height focus point
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement