void Update() { if (!canLock) { return; } if (Input.GetMouseButton(0) && Screen.lockCursor == false) { SetPause(false); } if (InputDB.GetButton("Escape")) { SetPause(true); } // Did we lose cursor locking? // eg. because the user pressed escape // or because he switched to another application // or because some script set Screen.lockCursor = false; if (!Screen.lockCursor && wasLocked) { wasLocked = false; SetPause(true); } // Did we gain cursor locking? else if (Screen.lockCursor && !wasLocked) { wasLocked = true; SetPause(false); } }
void Update() { if (InputDB.GetButtonDown("Fire2")) { Cycle(); } }
public static void SetPause(bool pause) { GameObject player = GameObject.FindWithTag("Player"); if (mobile) { return; } InputDB.ResetInputAxes(); if (pause) { PlayerWeapons.playerActive = false; //Screen.lockCursor = false; Time.timeScale = 0; player.BroadcastMessage("Freeze", SendMessageOptions.DontRequireReceiver); } else { unPaused = true; Time.timeScale = 1; Screen.lockCursor = true; PlayerWeapons.playerActive = true; player.BroadcastMessage("UnFreeze", SendMessageOptions.DontRequireReceiver); } }
// Update is called once per frame void Update() { // Get the input vector from kayboard or analog stick Vector3 directionVector = new Vector3(InputDB.GetAxis("Horizontal"), 0, InputDB.GetAxis("Vertical")); if (directionVector != Vector3.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway float directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; // Make sure the length is no bigger than 1 directionLength = Mathf.Min(1, directionLength); // Make the input vector more sensitive towards the extremes and less sensitive in the middle // This makes it easier to control slow speeds when using analog sticks directionLength = directionLength * directionLength; // Multiply the normalized direction vector by the modified length directionVector = directionVector * directionLength; } // Apply the direction to the CharacterMotorDB motor.inputMoveDirection = transform.rotation * directionVector; motor.inputJump = InputDB.GetButton("Jump"); }
void LateUpdate() { if (!playerActive) { return; } if (InputDB.GetButtonDown("Fire1") && canKickback) { canKickback = false; } else if (InputDB.GetButtonUp("Fire1")) { canKickback = true; gameObject.BroadcastMessage("ReleaseFire", 1, SendMessageOptions.DontRequireReceiver); } if (weapons[selectedWeapon] != null) { if (/*!InputDB.GetButton ("Fire1") || */ Time.time > weapons[selectedWeapon].GetComponent <GunScript>().nextFireTime) { BroadcastMessage("Cooldown"); } } if (InputDB.GetButtonUp("Aim")) { gameObject.SendMessageUpwards("ReleaseFire", 2, SendMessageOptions.DontRequireReceiver); } }
void Update() { if (!walking) { notWalkingTime = Time.time - stopWalkingTime; } else { notWalkingTime = 0; } Vector3 weaponCameraLocalPos = weaponCamera.transform.localPosition; if (weaponCameraLocalPos.y > standardCamHeight) { weaponCameraLocalPos.y = standardCamHeight; } else if (weaponCameraLocalPos.y < crouchingCamHeight) { weaponCameraLocalPos.y = crouchingCamHeight; } if (grounded) { if (InputDB.GetButtonDown("Crouch")) { if (crouching) { stopCrouching = true; NormalSpeed(); return; } if (!crouching) { Crouch(); } } } if (crouching) { if (weaponCameraLocalPos.y > crouchingCamHeight) { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y - crouchDeltaHeight * Time.deltaTime * 8, crouchingCamHeight, standardCamHeight); } } else { if (weaponCameraLocalPos.y < standardCamHeight) { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y + standardCamHeight * Time.deltaTime * 8, 0, standardCamHeight); } } weaponCamera.transform.localPosition = weaponCameraLocalPos; }
public void Update() { if (InputDB.GetButtonDown("Store")) { if (!storeActive && canActivate && !GunScript.takingOut && !GunScript.puttingAway) { activateStore(); } else if (storeActive) { deActivateStore(); } } }
void FixedUpdate() { if (grounded && PlayerWeapons.canMove) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(InputDB.GetAxis("Horizontal"), 0, InputDB.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (InputDB.GetButton("Jump")) { moveDirection.y = jumpSpeed; if (crouching) { stopCrouching = true; NormalSpeed(); } } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller CharacterController controller = GetComponent <CharacterController>(); CollisionFlags flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; if ((Mathf.Abs(moveDirection.x) > 0) && grounded || (Mathf.Abs(moveDirection.z) > 0 && grounded)) { if (!walking) { walking = true; BroadcastMessage("Walking", SendMessageOptions.DontRequireReceiver); } } else if (walking) { walking = false; stopWalkingTime = Time.time; BroadcastMessage("StopWalking", SendMessageOptions.DontRequireReceiver); } }
void Update() { if (player == null) { return; } if (ladder) { if (Input.GetButtonDown("Jump")) { ReleasePlayer(); } float lastVal = val; val += InputDB.GetAxis("Vertical") * sensitivity * Time.deltaTime; val = Mathf.Clamp01(val); soundAmt -= Mathf.Abs(lastVal - val); if (soundAmt <= 0) { soundAmt = soundInterval; GetComponent <AudioSource>().Play(); } // player.position.y = Mathf.Lerp(transform.position.y, exitPos.position.y, val); player.position = new Vector3(player.position.x, Mathf.Lerp(transform.position.y, exitPos.position.y, val), player.position.z); if (val == 1 && !GunScript.takingOut && !GunScript.puttingAway) { ExitLadder(); } if (val < minHeight && ((lastVal > val) || val == 0) && !GunScript.takingOut && !GunScript.puttingAway) { ReleasePlayer(); } } }
void Update() { if (!GunScript1.gunActive) { if (transform.localPosition != hipPosition) { transform.localPosition = hipPosition; } if (transform.localEulerAngles != hipRotation) { transform.localEulerAngles = hipRotation; } sprinting = false; return; } staticAiming = aiming; //Replenish Sprint time float tempSprintTime = 0; if (controller.velocity.magnitude == 0) { tempSprintTime = sprintEndTime; } if (sprintNum < sprintDuration && !sprinting && Time.time > tempSprintTime) { if (controller.velocity.magnitude == 0) { sprintNum = Mathf.Clamp(sprintNum + sprintAddStand * Time.deltaTime, 0, sprintDuration); } else { sprintNum = Mathf.Clamp(sprintNum + sprintAddWalk * Time.deltaTime, 0, sprintDuration); } } if (sprintNum > sprintMin) { exhausted = false; } //Turn on scope if it is time if ((inScope && !aiming) || (zoomed && !aiming)) { inScope = false; zoomed = false; var gos = GetComponentsInChildren <Renderer>(); foreach (Renderer go in gos) { if (go.name != "muzzle_flash") { go.enabled = true; } } } //Reset Camera if (!aiming && cmra.GetComponent <Camera>().fieldOfView != PlayerWeapons.fieldOfView) { if (sightsZoom1 && !scoped) { cmra.GetComponent <Camera>().fieldOfView = Mathf.Lerp(cmra.GetComponent <Camera>().fieldOfView, PlayerWeapons.fieldOfView, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / aimRate)); wcmra.GetComponent <Camera>().fieldOfView = Mathf.Lerp(wcmra.GetComponent <Camera>().fieldOfView, PlayerWeapons.fieldOfView, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / aimRate)); } else { cmra.GetComponent <Camera>().fieldOfView = PlayerWeapons.fieldOfView; wcmra.GetComponent <Camera>().fieldOfView = PlayerWeapons.fieldOfView; } } staticRate = aimRate; //aiming if (InputDB.GetButton("Aim") && canAim && PlayerWeapons.canAim && selected && !sprinting /*&& !GunScript1.sprint*/ && Avoidance.canAim) { if (!aiming) { aimStartTime = Time.time + aimRate; scopeTime = Time.time + aimRate; aiming = true; canSwitchWeaponAim = false; startPosition = transform.localPosition; startRotation = transform.localEulerAngles; curVect = aimPosition - transform.localPosition; player.BroadcastMessage("Aiming", zoomFactor, SendMessageOptions.DontRequireReceiver); } //Align to position GunToRotation(aimRotation, aimRate); if (aiming) { transform.localPosition = Vector3.Slerp(startPosition, aimPosition, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / aimRate)); } //Turn on scope if it's time if (scoped && selected && Time.time >= scopeTime && !inScope) { inScope = true; var go = GetComponentsInChildren <Renderer>(); foreach (Renderer g in go) { if (g.gameObject.name != "Sparks") { g.enabled = false; } } cmra.GetComponent <Camera>().fieldOfView = PlayerWeapons.fieldOfView / zoomFactor; } //Otherwise if sights zoom then zoom in camera if (sightsZoom && selected && !zoomed && !scoped) { cmra.GetComponent <Camera>().fieldOfView = Mathf.Lerp(cmra.GetComponent <Camera>().fieldOfView, PlayerWeapons.fieldOfView / zoomFactor, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / aimRate)); wcmra.GetComponent <Camera>().fieldOfView = Mathf.Lerp(wcmra.GetComponent <Camera>().fieldOfView, PlayerWeapons.fieldOfView / zoomFactor, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / aimRate)); if (cmra.GetComponent <Camera>().fieldOfView == PlayerWeapons.fieldOfView / zoomFactor) { zoomed = true; } } //sprinting } else if (InputDB.GetButton("Sprint") && !InputDB.GetButton("Aim") && canSprint && PlayerWeapons.canSprint && selected && !aiming && CM.grounded && !exhausted && (controller.velocity.magnitude > CM.movement.minSprintSpeed || (/*CM.prone || */ CharacterMotorDB.crouching))) { sprintNum = Mathf.Clamp(sprintNum - Time.deltaTime, 0, sprintDuration); aiming = false; if (!sprinting) { aimStartTime = Time.time + sprintRate; curVect = sprintPosition - transform.localPosition; sprinting = true; player.BroadcastMessage("Sprinting", SendMessageOptions.DontRequireReceiver); canSwitchWeaponAim = false; startPosition = transform.localPosition; startRotation = transform.localEulerAngles; } //Align to position transform.localPosition = Vector3.Slerp(startPosition, sprintPosition, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / sprintRate)); GunToRotation(sprintRotation, sprintRate); //Check if we're out of sprint if (sprintNum <= 0) { exhausted = true; sprintEndTime = Time.time + recoverDelay; } //returning to normal } else { if ((aiming || sprinting || switching)) { if (sprinting) { sprintEndTime = Time.time + recoverDelay; player.BroadcastMessage("StopSprinting", SendMessageOptions.DontRequireReceiver); } switching = false; aimStartTime = Time.time + retRate; startPosition = transform.localPosition; startRotation = transform.localEulerAngles; sprinting = false; canSwitchWeaponAim = true; curVect = hipPosition - transform.localPosition; SendMessageUpwards("NormalSpeed", SendMessageOptions.DontRequireReceiver); if (aiming) { aiming = false; player.BroadcastMessage("StopAiming", SendMessageOptions.DontRequireReceiver); } } //Align to position transform.localPosition = Vector3.Slerp(startPosition, hipPosition, Mathf.SmoothStep(0, 1, 1 - (aimStartTime - Time.time) / retRate)); GunToRotation(hipRotation, retRate); } staticAiming = aiming; sprintingPublic = sprinting; }
void Update() { if (freeze || !PlayerWeapons.playerActive) { return; } if (retSensitivity > 0) { retSensitivity *= -1; } if (useLookMotion && PlayerWeapons.canLook) { Quaternion xQuaternion; Quaternion yQuaternion; // Read the mouse input axis rotationX += InputDB.GetAxis("Mouse X") * sensitivityX; rotationY += InputDB.GetAxis("Mouse Y") * sensitivityY; rotationZ += InputDB.GetAxis("Mouse X") * sensitivityZ; rotationX = ClampAngle(rotationX, minimumX, maximumX); rotationY = ClampAngle(rotationY, minimumY, maximumY); rotationZ = ClampAngle(rotationZ, -actualZRange, actualZRange); if (Mathf.Abs(Input.GetAxis("Mouse X")) < .05) { if (sensitivityX > 0) { rotationX -= rotationX * Time.deltaTime * retSensitivity * 7; rotationZ -= rotationZ * Time.deltaTime * retSensitivity * 7; rotationY += rotationY * Time.deltaTime * retSensitivity * 7; } else { rotationX += rotationX * Time.deltaTime * retSensitivity * 7; rotationZ += rotationZ * Time.deltaTime * retSensitivity * 7; rotationY += rotationY * Time.deltaTime * retSensitivity * 7; } } xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); Quaternion zQuaternion = Quaternion.AngleAxis(rotationZ, Vector3.forward); yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left); transform.localRotation = Quaternion.Lerp(transform.localRotation, originalRotation * xQuaternion * yQuaternion * zQuaternion, Time.deltaTime * 10); } if (useWalkMotion) { //Velocity-based changes Vector3 relVelocity = transform.InverseTransformDirection(PlayerWeapons.CM.movement.velocity); float zVal; float xVal; float xVal2; lastOffset = posOffset; float s = new Vector3(PlayerWeapons.CM.movement.velocity.x, 0, PlayerWeapons.CM.movement.velocity.z).magnitude / 14; if (!AimMode.staticAiming) { float xPos = Mathf.Clamp(relVelocity.x * xPosMoveSensitivity, -xPosMoveRange * s, xPosMoveRange * s); posOffset.x = Mathf.Lerp(posOffset.x, xPos, Time.deltaTime * xPosAdjustSpeed); // + startPos.x; float zPos = Mathf.Clamp(relVelocity.z * zPosMoveSensitivity, -zPosMoveRange * s, zPosMoveRange * s); posOffset.z = Mathf.Lerp(posOffset.z, zPos, Time.deltaTime * zPosAdjustSpeed); // + startPos.z; } else { posOffset.x = Mathf.Lerp(posOffset.x, 0, Time.deltaTime * xPosAdjustSpeed * 3); // + startPos.x; posOffset.z = Mathf.Lerp(posOffset.z, 0, Time.deltaTime * zPosAdjustSpeed * 3); // + startPos.z; } //Apply Jostle lastJostle = curJostle; curJostle = Vector3.Lerp(curJostle, jostleAmt, Time.deltaTime * 10); jostleAmt = Vector3.Lerp(jostleAmt, Vector3.zero, Time.deltaTime * 3); lastTarget = curTarget; curTarget = Vector3.Lerp(curTarget, posOffset, Time.deltaTime * 8); transform.localPosition += curTarget - lastTarget; transform.localPosition += curJostle - lastJostle; } }
void Update() { if (!playerActive) { return; } /************************Interact****************************/ if (interactDistance > 0) { //Set up ray Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2.0f, Screen.height / 2.0f, 0)); if (Physics.Raycast(ray, out hit, interactDistance, interactMask)) { //We hit something new if (lastHit != hit.transform) { //Last object isn't still highlighted if (lastHit) { lastHit.SendMessage("HighlightOff", SendMessageOptions.DontRequireReceiver); } //New one is lastHit = hit.transform; lastHit.SendMessage("HighlightOn", SendMessageOptions.DontRequireReceiver); } } else if (lastHit != null) { //We hit nothing, but still have a object highlighted, so unhighlight it lastHit.SendMessage("HighlightOff", SendMessageOptions.DontRequireReceiver); lastHit = null; } //Interact if (InputDB.GetButtonDown("Interact") && lastHit != null) { lastHit.SendMessage("Interact", this.gameObject, SendMessageOptions.DontRequireReceiver); } } /**********************Fire & Reload******************************/ // Did the user press fire? if (InputDB.GetButton("Fire1") && (autoFire || charge) && canFire) { transform.root.BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); } else if (InputDB.GetButtonDown("Fire1") && canFire) { transform.root.BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); } if (InputDB.GetButton("Fire2") && canFire && (autoFire || charge)) { BroadcastMessage("Fire2", SendMessageOptions.DontRequireReceiver); } else if (InputDB.GetButtonDown("Fire2") && canFire) { BroadcastMessage("Fire2", SendMessageOptions.DontRequireReceiver); } if (InputDB.GetButtonDown("Reload")) { BroadcastMessage("Reload", SendMessageOptions.DontRequireReceiver); } /*************************Weapon Switching***************************/ if (!AimMode.canSwitchWeaponAim || hidden || !canSwitchWeapon || Avoidance.collided) { return; } if (InputDB.GetButtonDown("SelectWeapon")) { int temp = WeaponSelector.selectedWeapon; if (weapons.Length > temp && (selectedWeapon != temp || weapons[selectedWeapon] == null) && temp >= 0) { if (weapons[temp] != null) { if (!weapons[temp].gameObject.GetComponent <WeaponInfo>().locked) { SelectWeapon(temp); selectedWeapon = temp; displayMessage = false; } else { SlotEmptyMessage(temp + 1); } } else { SlotEmptyMessage(temp + 1); } } } }
void Update() { if (freeze || !PlayerWeapons.canLook || individualFreeze) { return; } Quaternion xQuaternion; Quaternion yQuaternion; float offsetVal; if (axes == RotationAxes.MouseX) { rotationX += InputDB.GetAxis("Mouse X") * sensitivityX; float xDecrease; if (totalOffsetX > 0) { xDecrease = Mathf.Clamp(resetSpeed * Time.deltaTime, 0, totalOffsetX); } else { xDecrease = Mathf.Clamp(resetSpeed * -Time.deltaTime, totalOffsetX, 0); } if (resetDelay > 0) { xDecrease = 0; resetDelay = Mathf.Clamp(resetDelay - Time.deltaTime, 0, resetDelay); } if (Random.value < .5) { offsetX *= -1; } if ((totalOffsetX < maxKickback && totalOffsetX >= 0) || (totalOffsetX > -maxKickback && totalOffsetX <= 0)) { totalOffsetX += offsetX; } else { //offsetX = 0; resetDelay *= .5f; } rotationX = ClampAngle(rotationX, minimumX, maximumX) + offsetX - xDecrease; if ((Input.GetAxis("Mouse X") * sensitivityX) < 0) { totalOffsetX += Input.GetAxis("Mouse X") * sensitivityX; } rotationX += Mathf.Sin(Time.time) * idleSway; totalOffsetX -= xDecrease; if (totalOffsetX < 0) { totalOffsetX = 0; } xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); tRotation = originalRotation * xQuaternion; offsetVal = Mathf.Clamp(totalOffsetX * smoothFactor, 1, smoothFactor); if (smooth) { transform.localRotation = Quaternion.Slerp(transform.localRotation, tRotation, Time.deltaTime * 25 / smoothFactor * offsetVal); } else { transform.localRotation = tRotation; } } else { rotationY += InputDB.GetAxis("Mouse Y") * sensitivityY; float yDecrease = Mathf.Clamp(resetSpeed * Time.deltaTime, 0, totalOffsetY); if (resetDelay > 0) { yDecrease = 0; resetDelay = Mathf.Clamp(resetDelay - Time.deltaTime, 0, resetDelay); } if (totalOffsetY < maxKickback) { totalOffsetY += offsetY; } else { offsetY = 0; resetDelay *= .5f; } rotationY = ClampAngle(rotationY, minimumY, maximumY) + offsetY - yDecrease; if ((Input.GetAxis("Mouse Y") * sensitivityY) < 0) { totalOffsetY += Input.GetAxis("Mouse Y") * sensitivityY; } rotationY += Mathf.Sin(Time.time) * idleSway; totalOffsetY -= yDecrease; if (totalOffsetY < 0) { totalOffsetY = 0; } yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left); tRotation = originalRotation * yQuaternion; offsetVal = Mathf.Clamp(totalOffsetY * smoothFactor, 1, smoothFactor); if (smooth) { transform.localEulerAngles = new Vector3(Quaternion.Slerp(transform.localRotation, tRotation, Time.deltaTime * 25 / smoothFactor * offsetVal).eulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z); } else { transform.localEulerAngles = new Vector3(tRotation.x, transform.localEulerAngles.y, transform.localEulerAngles.z); ; } } offsetY = 0; offsetX = 0; }
void Start() { thisObj = this; }
void Update() { weaponsInactive = (PlayerWeapons.PW.weapons[PlayerWeapons.PW.selectedWeapon] == null); if (!weaponsInactive) { weaponsInactive = (PlayerWeapons.PW.weapons[PlayerWeapons.PW.selectedWeapon].GetComponent <GunScript>().gunActive == false); } if (!weaponsInactive) { return; } //Replenish Sprint time float tempSprintTime = 0; if (PlayerWeapons.controller.velocity.magnitude == 0) { tempSprintTime = sprintEndTime; } if (AimMode.sprintNum < values.sprintDuration && !AimMode.sprintingPublic && Time.time > tempSprintTime) { if (PlayerWeapons.controller.velocity.magnitude == 0) { AimMode.sprintNum = Mathf.Clamp(AimMode.sprintNum + values.sprintAddStand * Time.deltaTime, 0, values.sprintDuration); } else { AimMode.sprintNum = Mathf.Clamp(AimMode.sprintNum + values.sprintAddWalk * Time.deltaTime, 0, values.sprintDuration); } } if (AimMode.sprintNum > values.sprintMin) { exhausted = false; } //Handle sprint if (InputDB.GetButton("Sprint") && !InputDB.GetButton("Aim") && PlayerWeapons.canSprint && CM.grounded && !exhausted && (PlayerWeapons.controller.velocity.magnitude > CM.movement.minSprintSpeed || (/*CM.prone || */ CharacterMotorDB.crouching))) { AimMode.sprintNum = Mathf.Clamp(AimMode.sprintNum - Time.deltaTime, 0, values.sprintDuration); if (!AimMode.sprintingPublic) { AimMode.sprintingPublic = true; BroadcastMessage("Sprinting", SendMessageOptions.DontRequireReceiver); AimMode.canSwitchWeaponAim = false; } //Check if we're out of sprint if (AimMode.sprintNum <= 0) { exhausted = true; sprintEndTime = Time.time + values.recoverDelay; } } else if (AimMode.sprintingPublic) { AimMode.sprintingPublic = false; BroadcastMessage("StopSprinting", SendMessageOptions.DontRequireReceiver); BroadcastMessage("NormalSpeed"); AimMode.canSwitchWeaponAim = true; } }
void Update() { if (paused) { movement.velocity = Vector3.zero; return; } if ((inputMoveDirection.x != 0 || inputMoveDirection.y != 0 || inputMoveDirection.z != 0) && grounded && PlayerWeapons.canMove) { if (!walking) { BroadcastMessage("Walking", SendMessageOptions.DontRequireReceiver); } walking = true; } else { if (walking) { BroadcastMessage("StopWalking", SendMessageOptions.DontRequireReceiver); } walking = false; } if (!useFixedUpdate) { UpdateFunction(); } /*if(weaponCamera.transform.localPosition.y > standardCamHeight){ * weaponCamera.transform.localPosition.y = standardCamHeight; * } else if(weaponCamera.transform.localPosition.y < crouchingCamHeight){ * weaponCamera.transform.localPosition.y = crouchingCamHeight; * }*/ if (grounded) { if (InputDB.GetButtonUp("Crouch") && PlayerWeapons.canCrouch) { if (!proneFrame) { if (!crouching && !prone) { /*if(PlayerWeapons.sprinting && movement.useDive && !diving){ * SetVelocity(transform.forward*25 + Vector3.up*12); * audio.volume = jumpSoundVolume; * audio.PlayOneShot(jumpSound); * diving = true; * lastCamSpeed = camSpeed; * crouching = false; * Prone(); * camSpeed = 1; * movement.crouchedTime = -1; * //prone = true; * } else {*/ Crouch(); } else if (crouching && AboveIsClear()) { crouching = false; stopCrouching = true; NormalSpeed(); } else if (prone && AboveIsClearProne()) { //crouching = false; //stopProne = true; prone = false; Crouch(); } } proneFrame = false; } else if (InputDB.GetButton("Crouch")) { if (movement.crouchedTime < 0) { movement.crouchedTime = Time.time; } if (Time.time > movement.crouchedTime + movement.proneHoldTime && movement.crouchedTime > 0 && !prone) { if (useProne) { Prone(); proneFrame = true; } movement.crouchedTime = -1; } } else { movement.crouchedTime = -1; } } Vector3 weaponCameraLocalPos = weaponCamera.transform.localPosition; if (crouching && !prone) { if (weaponCameraLocalPos.y > crouchingCamHeight) { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y - crouchDeltaHeight * Time.deltaTime * camSpeed, crouchingCamHeight, standardCamHeight); } else { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y + crouchDeltaHeight * Time.deltaTime * camSpeed, proneCamHeight, crouchingCamHeight); } } else if (prone) { if (weaponCameraLocalPos.y > proneCamHeight) { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y - crouchDeltaHeight * Time.deltaTime * camSpeed, proneCamHeight, weaponCameraLocalPos.y); } else if (!hitProne) { GunLook.jostleAmt = new Vector3(-.075f, -.12f, 0); CamSway.jostleAmt = new Vector3(-.01f, -.03f, 0); hitProne = true; GetComponent <AudioSource>().volume = proneLandSoundVolume; GetComponent <AudioSource>().PlayOneShot(proneLandSound); } } else { if (weaponCameraLocalPos.y < standardCamHeight) { weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y + standardCamHeight * Time.deltaTime * camSpeed, proneCamHeight, standardCamHeight); } } weaponCamera.transform.localPosition = weaponCameraLocalPos; }
void LateUpdate() { float maxLean = 0; if (InputDB.GetButton("LeanRight") && PlayerWeapons.CM.grounded && !CharacterMotorDB.walking) { if (!leaning || left) { leaning = true; targetPos = startPos + leanAmount; targetRot = -leanRotate; left = false; colliding = false; } } else if (InputDB.GetButton("LeanLeft") && PlayerWeapons.CM.grounded && !CharacterMotorDB.walking) { if (!leaning || !left) { leaning = true; targetPos = startPos - leanAmount; targetRot = leanRotate; left = true; colliding = false; } } else if (leaning) { colliding = false; leaning = false; targetPos = startPos; } if (left && leaning) { maxLean = Check(-1 * transform.right); targetPos = Mathf.Max(startPos - leanAmount, -maxLean + skinWidth); } else if (leaning) { maxLean = Check(transform.right); targetPos = Mathf.Min(startPos + leanAmount, maxLean - skinWidth); } Vector3 localpos = transform.localPosition; localpos.x = Mathf.Lerp(transform.localPosition.x, targetPos, Time.deltaTime * leanRate * 4); Vector3 localEuler = transform.localEulerAngles; localEuler.z = Mathf.LerpAngle(0, targetRot, Mathf.Abs(transform.localPosition.x) / leanAmount); //clamp our position if necessary if (colliding) { localpos.x = Mathf.Clamp(transform.localPosition.x, -maxLean, maxLean); } transform.localPosition = localpos; transform.localEulerAngles = localEuler; }