/// @param deltaMovement /// The movement to apply /// /// @return Whether the camera was moved - false if reaching its bounds /// private bool MoveCamera(Vector2 deltaMovement) { bool moved = false; var dragDelta = deltaMovement; // Inverse axis if (m_view.m_inverseX == true) { dragDelta.x *= -1; } if (m_view.m_inverseY == true) { dragDelta.y *= -1; } m_offset += m_view.CameraHolder.TransformDirection((Vector3)(dragDelta * m_view.Camera.orthographicSize / m_view.Camera.pixelHeight * 2.0f)); var position = m_origin + m_offset; if (m_view.m_boundlessDrag == false) { position.x = Mathf.Clamp(position.x, m_minPos.x, m_maxPos.x); position.y = Mathf.Clamp(position.y, m_minPos.y, m_maxPos.y); m_offset = position - m_origin; } if (m_view.CameraHolder.position != position) { moved = true; m_view.CameraHolder.position = position; OnCameraMoved.SafeInvoke(position); } return(moved); }
public IEnumerator MoveCameraXAxis(Vector3 destination) { Vector3 cameraStartPosition = transform.position; float currentTime = 0; while (currentTime < cameraAnimationTime) { currentTime += Time.deltaTime; transform.position = new Vector3(Mathf.Lerp(cameraStartPosition.x, destination.x, currentTime / cameraAnimationTime), cameraStartPosition.y, cameraStartPosition.z); yield return(new WaitForEndOfFrame()); } OnCameraMoved?.Invoke(this, EventArgs.Empty); OnCameraMoved = delegate { }; }
private void LateUpdate() { if (PlayerController.PlayerCurrentState == PlayerController.PlayerState.Interacting) { return; } float distanceToCamp = Vector3.Distance(new Vector3(500, 0, 520), PlayerController.PlayerPosition); if (distanceToCamp < _campSnapDistance) { OnCameraOnCamp?.Invoke(); // Camera position transform.position = new Vector3(497.9f, 21.1f, 496.2f); } else { Vector2 targetScreenSpace = _mainCamera.WorldToScreenPoint(PlayerController.PlayerPosition); targetScreenSpace = _mainCamera.ScreenToViewportPoint(targetScreenSpace); float distanceToCenter = Vector2.Distance(new Vector2(0.5f, 0.5f), targetScreenSpace); _canFollow = distanceToCenter > _invalidBound; if (distanceToCenter > 1) { //reset _movementOffset = _offset; transform.position = PlayerController.PlayerPosition + _movementOffset; } if (!_canFollow) { return; } transform.position = PlayerController.PlayerPosition + _offset; OnCameraMoved?.Invoke(); } }