Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var target : Transform;
- var distance = 10.0;
- var maxDistance = 10.0;
- var xSpeed = 250.0;
- var ySpeed = 120.0;
- var yMinLimit = -20;
- var yMaxLimit = 80;
- public var x = 0.0;
- public var y = 0.0;
- private var auxX = 0.0;
- private var auxY = 0.0;
- var scoped : boolean = false;
- private var isMoving : boolean = false;
- private var startPos = Vector3.zero;
- public var dampSpeed : float;
- private var playerGUI : PlayerGUI;
- private var playerWeapons : PlayerWeapons;
- private var controller : FPSWalker;
- private var vignetting : Vignetting;
- private var animations : NewAnimations1;
- private var zoomSpeed = 3.0f;
- private var isCounting : boolean = true;
- private var origFOV : int;
- private var soldierCam : Camera;
- @script AddComponentMenu("Camera-Control/Mouse Orbit")
- function Awake() {
- playerGUI = GameObject.Find("Localscripts").GetComponent(PlayerGUI);
- soldierCam = transform.GetComponent(Camera);
- playerWeapons = transform.parent.GetComponent(PlayerWeapons);
- controller = transform.parent.GetComponent(FPSWalker);
- vignetting = transform.GetComponent(Vignetting);
- animations = transform.parent.GetComponent(NewAnimations1);
- origFOV = soldierCam.fieldOfView;
- }
- function Start () {
- var angles = transform.eulerAngles;
- startPos = transform.position;
- auxX = x = angles.y;
- auxY = y = angles.x;
- // Make the rigid body not change rotation
- if (rigidbody)
- rigidbody.freezeRotation = true;
- }
- function LateUpdate () {
- // Stop script if you're dead
- if (target && !animations.dead) {
- x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
- y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
- // Update target height based on stance
- if(animations.standing && target.localPosition.y != 2.2) {
- target.localPosition.y = 2.2;
- } else if(animations.crouched && target.localPosition.y != 1.2) {
- target.localPosition.y = 1.75;
- }
- // Scope, Camera FOV and camera effects
- if(playerWeapons.weaponType != "SniperRifle") {
- playerGUI.sniperScope = false;
- if(Input.GetAxis("Fire2") != 0.0 && !controller.sprinting) {
- if(vignetting.blurVignette < 0.85) {
- vignetting.blurVignette = Mathf.Lerp(vignetting.blurVignette, 0.9, Time.deltaTime * 5);
- }
- scoped = true;
- } else {
- if(vignetting.blurVignette > 0.45) {
- vignetting.blurVignette = Mathf.Lerp(vignetting.blurVignette, 0.4, Time.deltaTime * 5);
- }
- if(vignetting.vignetteIntensity > 0.0) {
- vignetting.vignetteIntensity = Mathf.Lerp(vignetting.vignetteIntensity, 0.0, Time.deltaTime * 20);
- }
- scoped = false;
- }
- } else {
- if(Input.GetAxis("Fire2") != 0.0 && !controller.sprinting) {
- playerGUI.sniperScope = true;
- soldierCam.fieldOfView = 5;
- scoped = true;
- } else {
- playerGUI.sniperScope = false;
- soldierCam.fieldOfView = 30;
- scoped = false;
- }
- }
- y = ClampAngle(y, yMinLimit, yMaxLimit);
- auxX = Mathf.Lerp(auxX, x, Time.deltaTime * dampSpeed);
- auxY = Mathf.Lerp(auxY, y, Time.deltaTime * dampSpeed);
- var rotation = Quaternion.Euler(auxY, auxX, 0);
- var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
- // Apply Position/Rotation
- transform.rotation = rotation;
- transform.position = position;
- // Collided with something other than "Target"
- var hit : RaycastHit;
- if (Physics.Linecast (target.position, transform.position, hit)){
- distance = hit.distance - 0.2;
- point = hit.point;
- }else if(Vector3.Distance(transform.position, point) > 0.3 && !scoped){
- distance += 5.0 * Time.deltaTime;
- }
- // Sprinting Camera Distance
- if(scoped && !controller.sprinting) {
- distance -= 10.0 * Time.deltaTime;
- }
- // Clamp camera distance
- distance = Mathf.Clamp(distance, 0.8, maxDistance);
- }
- }
- static function ClampAngle (angle : float, min : float, max : float) {
- if (angle < -360)
- angle += 360;
- if (angle > 360)
- angle -= 360;
- return Mathf.Clamp (angle, min, max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement