public void DoMoveTo(Vector2Int inPatrolRange) { PlayAnimation(ActorActions.Move); gameView.transform.Translate(new Vector3(_directionX * (Time.fixedDeltaTime + _view.Profile.speed), 0, 0)); if (_facing == ActorFacing.Right && gameView.transform.localPosition.x > inPatrolRange.y || _facing == ActorFacing.Left && gameView.transform.localPosition.x < inPatrolRange.x) { _view.SetDirectionX(InvertDirection()); } _sightRay.SetDirection(GetDirection()); }
private void Move(float inHorizontal, float inSpeed) { if (_collider == null || _currentAction == ActorActions.Shoot) { return; } if ((int)inHorizontal != 0) { // -------------------------------------------------------------------------------- // player is on move : play the desired animation // -------------------------------------------------------------------------------- if (!_playerInTheAir) { PlayAnimation(ActorActions.Move); } _directionX = inHorizontal < 0 ? -1 : 1; _facing = inHorizontal < 0 ? ActorFacing.Left : ActorFacing.Right; _levelColliderSensor.SetDirection(GetDirection()); gameView.SetDirectionX(_directionX); horizontalMove = inHorizontal; } else { // -------------------------------------------------------------------------------- // Player is idle : play the desired animation // -------------------------------------------------------------------------------- horizontalMove = 0; if (!_playerInTheAir && _currentAction != ActorActions.Shoot) { PlayAnimation(ActorActions.Idle); } } // -------------------------------------------------------------------------------- // Translate target view // -------------------------------------------------------------------------------- if (_isBlocked) { return; } gameView.position = gameView.transform.position; gameView.transform.Translate(new Vector3(horizontalMove * (Time.fixedDeltaTime + inSpeed), 0, 0)); }