Hello, I am trying to make a scope for a gun, and have it zoom in a little bit... I have the variable "zoomangle" but it doesn't seem to even acknowledge it. Here is my code for the Gun: Code (csharp): var cameraObject : GameObject; @HideInInspector var targetXRotation : float; @HideInInspector var targetYRotation : float; @HideInInspector var targetXRotationV : float; @HideInInspector var targetYRotationV : float; var rotateSpeed : float = 0.3; var holdHeight : float = -0.5; var holdSide : float = 0.5; var racioHipHold : float = 1; var hipToAimSpeed : float = 0.1; @HideInInspector var racioHipHoldV : float; var aimRacio : float = 0.4; var zoomAngle : float = 30; function Update () { cameraObject.GetComponent(MouseLookScript).current TargetCameraAngle = zoomAngle; if (Input.GetButton("Fire2")){ cameraObject.GetComponent(MouseLookScript).currentAimRacio = aimRacio; racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);} if (Input.GetButton("Fire2") == false){ cameraObject.GetComponent(MouseLookScript).currentAimRacio = 1; racioHipHold = Mathf.SmoothDamp(racioHipHold, 1, racioHipHoldV, hipToAimSpeed);} transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * racioHipHold, holdHeight * racioHipHold, 0)); targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed); targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed); transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0); } and camera Code (csharp): var defaultCameraAngle : float = 60; @HideInInspector var currentTargetCameraAngle : float = 60; @HideInInspector var racioZoom : float = 1; @HideInInspector var racioZoomV : float; var racioZoomSpeed : float = 0.2; var lookSensitivity : float = 5; @HideInInspector var yRotation : float; @HideInInspector var xRotation : float; @HideInInspector var currentYRotation : float; @HideInInspector var currentXRotation : float; @HideInInspector var yRotationV : float; @HideInInspector var xRotationV : float; var lookSmoothDamp : float = 0.1; @HideInInspector var currentAimRacio : float = 1; function Update () { if (currentAimRacio == 1) racioZoom = Mathf.SmoothDamp(racioZoom, 1, racioZoomV, racioZoomSpeed); else racioZoom = Mathf.SmoothDamp(racioZoom, 0, racioZoomV, racioZoomSpeed); camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, racioZoom); yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRacio; xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRacio; xRotation = Mathf.Clamp(xRotation, -90, 90); currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp); currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp); transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0); }
"Assets/Gunscript.js(26,55): UCE0001: ';' expected. instert a semicolon at the end." I've been getting this error and I'm irritated as hell... THERE IS ALREADY A FRAKKING SEMI-COLON!
As far as I'm concerned, that error may as well read: "There is something wrong with this line. Fix it." Anyways, you left a space at this line between current and TargetCameraAngle.
Now I have another problem... It zooms in but it takes a while to zoom back out... Also, I cannot move while aiming.. (that could be because of a variable I have set, I'll check) EDIT Just checked, Nope, no clue why I can't aim while aiming...
No, I let go of right click and it takes a while before it zooms out... when it does, it does it at a regular rate. But it takes a while for it to happen
What about (for the camera) Code (csharp): var defaultCameraAngle : float = 60; @HideInInspector var currentTargetCameraAngle : float = 60; @HideInInspector var racioZoom : float = 1; @HideInInspector var racioZoomV : float; var racioZoomSpeed : float = 0.2; var lookSensitivity : float = 5; @HideInInspector var yRotation : float; @HideInInspector var xRotation : float; @HideInInspector var currentYRotation : float; @HideInInspector var currentXRotation : float; @HideInInspector var yRotationV : float; @HideInInspector var xRotationV : float; var lookSmoothDamp : float = 0.1; @HideInInspector var currentAimRacio : float = 1; function Update () { racioZoom = Mathf.SmoothDamp(racioZoom, currentAimRacio , racioZoomV, racioZoomSpeed); camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, racioZoom); yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRacio; xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRacio; xRotation = Mathf.Clamp(xRotation, -90, 90); currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp); currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp); transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0); }
It's a mistake in Eteeski's tutorials that everyone looked funny at, said "meh, maybe it was spelled like that for a reason" and moved on. What do you mean by can't aim? Can't turn? Can't zoom out? No ADS?
Code (csharp): var defaultCameraAngle : float = 60; @HideInInspector var currentTargetCameraAngle : float = 60; @HideInInspector var racioZoom : float = 1; @HideInInspector var racioZoomV : float; var racioZoomSpeed : float = 0.2; var lookSensitivity : float = 5; @HideInInspector var yRotation : float; @HideInInspector var xRotation : float; @HideInInspector var currentYRotation : float; @HideInInspector var currentXRotation : float; @HideInInspector var yRotationV : float; @HideInInspector var xRotationV : float; var lookSmoothDamp : float = 0.1; @HideInInspector var currentAimRacio : float = 1; function Update () { racioZoom = Mathf.SmoothDamp(racioZoom, currentAimRacio , racioZoomV, racioZoomSpeed); camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, racioZoom); yRotation += Input.GetAxis("Mouse X") * lookSensitivity; xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity; xRotation = Mathf.Clamp(xRotation, -90, 90); currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp); currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp); transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0); } Just to let you know, I have to do a lot of guessing, as I don't have the game in front of me. Anyways, try this camera script.