void Start() { _currTilt = transform.rotation.eulerAngles.x; _currRotation = transform.rotation.eulerAngles.y; _distance = _distanceRange.Clamp(_distance); _lookAt = transform.position; _initialDistance = _currDistance = _distance; _initialRotation = _rotation = _currRotation; _initialTilt = _tilt = _currTilt; // set our current values to the desired values so that we don't "slide in" CreateTarget(); }
public void Zoom(float value) { if (_cam.orthographic) { _cam.orthographicSize = _scrollLimit.Clamp(_cam.orthographicSize + (value * _scrollSpeed)); } else { _cam.fieldOfView = _scrollLimit.Clamp(_cam.fieldOfView + (value * _scrollSpeed)); } if (_clampPos) { Refresh(); } }
protected void LateUpdate() { if (IsFollowing) { _lookAt = _followTarget.position; } else { _moveVector.y = 0; _lookAt += Quaternion.Euler(0, _rotation, 0) * _moveVector; _lookAt.y = GetHeightAt(_lookAt.x, _lookAt.z); } _lookAt.y += _lookAtHeightOffset; if (_limitPos && !_cameraLimitSpace.bounds.Contains(_lookAt)) { _lookAt = _cameraLimitSpace.ClosestPointOnBounds(_lookAt); } _tilt = _tiltRange.Clamp(_tilt); _distance = _distanceRange.Clamp(_distance); //LookAt = new Vector3(Mathf.Clamp(LookAt.x, MinBounds.x, MaxBounds.x), // Mathf.Clamp(LookAt.y, MinBounds.y, MaxBounds.y), Mathf.Clamp(LookAt.z, MinBounds.z, MaxBounds.z)); if (_smoothing) { _currRotation = Mathf.LerpAngle(_currRotation, _rotation, TimeManager.DeltaUnscaled * _rotationDampening); _currDistance = Mathf.Lerp(_currDistance, _distance, TimeManager.DeltaUnscaled * _zoomDampening); _currTilt = Mathf.LerpAngle(_currTilt, _tilt, TimeManager.DeltaUnscaled * _tiltDampening); _target.transform.position = Vector3.Lerp(_target.transform.position, _lookAt, TimeManager.DeltaUnscaled * _moveDampening); } else { _currRotation = _rotation; _currDistance = _distance; _currTilt = _tilt; _target.transform.position = _lookAt; } _moveVector = Vector3.zero; // if we're following AND forcing behind, override the rotation to point to target (with offset) if (IsFollowing && _followBehind) { ForceFollowBehind(); } // optionally, we'll check to make sure the target is visible // Note: we only do this when following so that we don't "jar" when moving manually if (IsFollowing && _targetVisbilityViaPhysics && DistanceToTargetIsLessThan(1f)) { EnsureTargetIsVisible(); } // recalculate the actual position of the camera based on the above UpdateCamera(); }