public bool Update(float deltaTime, ref AxisState axis) { if (!string.IsNullOrEmpty(name)) { try { inputValue = CinemachineCore.GetInputAxis(name); } catch (ArgumentException) { } } //catch (ArgumentException e) { Debug.LogError(e.ToString()); } var inverted = isInverted ? -1 : 1; var input = inputValue * sensitivity * multiplier * inverted; if (deltaTime < Epsilon) { mCurrentSpeed = 0; } else { var speed = input / deltaTime; var dampTime = Mathf.Abs(speed) < Mathf.Abs(mCurrentSpeed) ? decelerationTime : accelerationTime; speed = mCurrentSpeed + Damper.Damp(speed - mCurrentSpeed, dampTime, deltaTime); mCurrentSpeed = speed; // Decelerate to the end points of the range if not wrapping var range = axis.m_MaxValue - axis.m_MinValue; if (!axis.m_Wrap && decelerationTime > Epsilon && range > Epsilon) { var v0 = ClampValue(ref axis, axis.Value); var v = ClampValue(ref axis, v0 + speed * deltaTime); var d = speed > 0 ? axis.m_MaxValue - v : v - axis.m_MinValue; if (d < 0.1f * range && Mathf.Abs(speed) > Epsilon) { speed = Damper.Damp(v - v0, decelerationTime, deltaTime) / deltaTime; } } input = speed * deltaTime; } axis.Value = ClampValue(ref axis, axis.Value + input); return(Mathf.Abs(inputValue) > Epsilon); }
public void AutoAdjustOffset(CinemachineVirtualCameraBase vcam, CameraState state, float deltaTime, ref Vector3 offset) { //在特定触发器的状态下不调整 if (m_IsTrigger) { Vector3 targetOffset = m_TriggerTarget - offset; offset += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime); return; } if (IsSelectAutoAdjustMode(AutoAdjustMode.Distance)) { if (m_AdjustNearFarRange.x >= m_AdjustNearFarRange.y) { return; } Quaternion inverseRawOrientation = Quaternion.Inverse(state.RawOrientation); float dis = (inverseRawOrientation * (vcam.Follow.position - state.FinalPosition)).z; if (dis < m_AdjustNearFarRange.x) { dis = dis - m_AdjustNearFarRange.x; offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime); } else if (dis > m_AdjustNearFarRange.y) { dis = dis - m_AdjustNearFarRange.y; offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime); } else { dis = -offset.z; offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime); } } if (IsSelectAutoAdjustMode(AutoAdjustMode.Turn)) { if (m_TurnAxisName == "" || m_AdjustRangeX.x >= m_AdjustRangeX.y) { return; } float value = CinemachineCore.GetInputAxis(m_TurnAxisName); if (value < 0) { float target = Mathf.Lerp(m_AdjustRangeX.y, m_AdjustRangeX.x, -value); float targetOffset = target - offset.x; offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime); } else if (value > 0) { float target = Mathf.Lerp(m_AdjustRangeX.y, m_AdjustRangeX.z, value); float targetOffset = target - offset.x; offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime); } else { float targetOffset = m_AdjustRangeX.y - offset.x; offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime); } } if (IsSelectAutoAdjustMode(AutoAdjustMode.RunFar)) { CinemachineCore.ActorData actor = CinemachineCore.Instance.GetActorData(); Quaternion inverseRawOrientation = Quaternion.Inverse(state.RawOrientation); Vector3 moveDirCamera = inverseRawOrientation * actor.MoveDirection; if (Mathf.Abs(moveDirCamera.x) > 0.5f || moveDirCamera.z < 0.0f) { float dis = (inverseRawOrientation * (vcam.Follow.position - state.FinalPosition)).z; dis = dis - m_AdjustMinDic; offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime); } else { float dis = -offset.z; offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime); } } }
private void Update() { Vector3 moveInput = Vector3.ClampMagnitude(new Vector3(Input.GetAxisRaw(horizontalMoveInput), 0, Input.GetAxisRaw(verticalMoveInput)), 1); Vector3 moveDir = transform.right * moveInput.x + transform.forward * moveInput.z; transform.Rotate(Vector3.up * CinemachineCore.GetInputAxis("Mouse X")); character.Move(moveDir.normalized); RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, pickUpRange) && hit.transform.GetComponent <Rigidbody>()) { if (CrosshairAnimator.Instance.animator.GetBool("Grabbing") == false) { CrosshairAnimator.Instance.animator.Play("hand_twitch"); } } else { if (CrosshairAnimator.Instance.animator.GetBool("Grabbing") == false) { CrosshairAnimator.Instance.animator.Play("default"); } } // Interact if (Input.GetButtonDown(interactInput)) { if (!heldobj && hit.transform.GetComponent <Rigidbody>()) { PickupObject(hit.transform.gameObject); } else { if (heldobj) { DropObject(); } } } if (heldobj) { //if (Vector3.Distance(heldobj.transform.position, holdParent.position) > 2.5f) { //Vector3 moveDirection = (holdParent.position - heldobj.transform.position); //heldobj.GetComponent<Rigidbody>().AddForce(moveDirection * moveForce); //} } // Jump if (Input.GetButtonDown(jumpInput)) { character.Jump(); } // Toggle Flashlight if (Input.GetButtonDown(flashlightInput)) { flashlight.SetActive(!flashlight.activeInHierarchy); } // Interact if (Input.GetButtonDown(interactInput)) { character.Interact(); } }