Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. var target : Transform;
  2. var distance = 10.0;
  3.  
  4. var maxDistance = 10.0;
  5.  
  6. var xSpeed = 250.0;
  7. var ySpeed = 120.0;
  8.  
  9. var yMinLimit = -20;
  10. var yMaxLimit = 80;
  11.  
  12. public var x = 0.0;
  13. public var y = 0.0;
  14.  
  15. private var auxX = 0.0;
  16. private var auxY = 0.0;
  17.  
  18. var scoped : boolean = false;
  19. private var isMoving : boolean = false;
  20. private var startPos = Vector3.zero;
  21.  
  22. public var dampSpeed : float;
  23.  
  24. private var playerGUI : PlayerGUI;
  25. private var playerWeapons : PlayerWeapons;
  26. private var controller : FPSWalker;
  27. private var vignetting : Vignetting;
  28. private var animations : NewAnimations1;
  29. private var zoomSpeed = 3.0f;
  30. private var isCounting : boolean = true;
  31. private var origFOV : int;
  32. private var soldierCam : Camera;
  33.  
  34. @script AddComponentMenu("Camera-Control/Mouse Orbit")
  35.  
  36. function Awake() {
  37. playerGUI = GameObject.Find("Localscripts").GetComponent(PlayerGUI);
  38. soldierCam = transform.GetComponent(Camera);
  39. playerWeapons = transform.parent.GetComponent(PlayerWeapons);
  40. controller = transform.parent.GetComponent(FPSWalker);
  41. vignetting = transform.GetComponent(Vignetting);
  42. animations = transform.parent.GetComponent(NewAnimations1);
  43. origFOV = soldierCam.fieldOfView;
  44. }
  45.  
  46. function Start () {
  47. var angles = transform.eulerAngles;
  48. startPos = transform.position;
  49. auxX = x = angles.y;
  50. auxY = y = angles.x;
  51.  
  52. // Make the rigid body not change rotation
  53. if (rigidbody)
  54. rigidbody.freezeRotation = true;
  55. }
  56.  
  57. function LateUpdate () {
  58. // Stop script if you're dead
  59. if (target && !animations.dead) {
  60. x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
  61. y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
  62.  
  63. // Update target height based on stance
  64. if(animations.standing && target.localPosition.y != 2.2) {
  65. target.localPosition.y = 2.2;
  66. } else if(animations.crouched && target.localPosition.y != 1.2) {
  67. target.localPosition.y = 1.75;
  68. }
  69.  
  70. // Scope, Camera FOV and camera effects
  71. if(playerWeapons.weaponType != "SniperRifle") {
  72. playerGUI.sniperScope = false;
  73. if(Input.GetAxis("Fire2") != 0.0 && !controller.sprinting) {
  74. if(vignetting.blurVignette < 0.85) {
  75. vignetting.blurVignette = Mathf.Lerp(vignetting.blurVignette, 0.9, Time.deltaTime * 5);
  76. }
  77. scoped = true;
  78. } else {
  79. if(vignetting.blurVignette > 0.45) {
  80. vignetting.blurVignette = Mathf.Lerp(vignetting.blurVignette, 0.4, Time.deltaTime * 5);
  81. }
  82. if(vignetting.vignetteIntensity > 0.0) {
  83. vignetting.vignetteIntensity = Mathf.Lerp(vignetting.vignetteIntensity, 0.0, Time.deltaTime * 20);
  84. }
  85. scoped = false;
  86. }
  87. } else {
  88. if(Input.GetAxis("Fire2") != 0.0 && !controller.sprinting) {
  89. playerGUI.sniperScope = true;
  90. soldierCam.fieldOfView = 5;
  91. scoped = true;
  92. } else {
  93. playerGUI.sniperScope = false;
  94. soldierCam.fieldOfView = 30;
  95. scoped = false;
  96. }
  97. }
  98.  
  99. y = ClampAngle(y, yMinLimit, yMaxLimit);
  100.  
  101. auxX = Mathf.Lerp(auxX, x, Time.deltaTime * dampSpeed);
  102. auxY = Mathf.Lerp(auxY, y, Time.deltaTime * dampSpeed);
  103.  
  104. var rotation = Quaternion.Euler(auxY, auxX, 0);
  105. var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
  106.  
  107. // Apply Position/Rotation
  108. transform.rotation = rotation;
  109. transform.position = position;
  110.  
  111. // Collided with something other than "Target"
  112. var hit : RaycastHit;
  113. if (Physics.Linecast (target.position, transform.position, hit)){
  114. distance = hit.distance - 0.2;
  115. point = hit.point;
  116. }else if(Vector3.Distance(transform.position, point) > 0.3 && !scoped){
  117. distance += 5.0 * Time.deltaTime;
  118. }
  119.  
  120. // Sprinting Camera Distance
  121. if(scoped && !controller.sprinting) {
  122. distance -= 10.0 * Time.deltaTime;
  123. }
  124. // Clamp camera distance
  125. distance = Mathf.Clamp(distance, 0.8, maxDistance);
  126. }
  127. }
  128.  
  129. static function ClampAngle (angle : float, min : float, max : float) {
  130. if (angle < -360)
  131. angle += 360;
  132. if (angle > 360)
  133. angle -= 360;
  134. return Mathf.Clamp (angle, min, max);
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement