// Update is called once per frame private void Update() { if (_previousPlayerDirection != PlayerDirection.CurrentDirection) { Debug.Log("Player change direction, Re-initialize state."); Initialize(); } // set Crosshair transform base on angle. var angle = Mathf.Lerp(_currentRotationAngle.From, _currentRotationAngle.To, _anglePercentage); Debug.Log($"Current angle {angle}"); transform.position = PositionFromAngle(angle) + PlayerPosition.position; _anglePercentage += Speed * Time.unscaledDeltaTime; Debug.Log($"angle percentage {_anglePercentage}"); if (_anglePercentage < 1f) { return; } _currentRotationAngle = FlipRotationAngle(_currentRotationAngle); _anglePercentage = 0f; }
private static RotationAngle FlipRotationAngle(RotationAngle rotationAngle) { return(new RotationAngle { From = rotationAngle.To, To = rotationAngle.From }); }
private void Initialize() { _currentRotationAngle = RotationAngleFromDirection(PlayerDirection.CurrentDirection); _previousPlayerDirection = PlayerDirection.CurrentDirection; _anglePercentage = 0f; }