Beispiel #1
0
        private void Move()
        {
            float verticalAxis   = Input.GetAxisRaw("Vertical");
            float horizontalAxis = Input.GetAxisRaw("Horizontal");

            if (verticalAxis != 0 || horizontalAxis != 0)
            {
                if (IsMoving == false)
                {
                    StartedMoving?.Invoke();
                    player.ChangeState((int)PlayerState.Moving);
                }
                IsMoving = true;

                var     transformCache = transform;
                Vector3 forward        = transformCache.forward;
                Vector3 right          = transformCache.right;

                Vector3 movementVector = (forward * verticalAxis) + (right * horizontalAxis);

                movementVector.Normalize();
                movementDirection = movementVector;
                rigidbody.AddForce(movementVector * currentSpeed, ForceMode.Impulse);
            }
            else
            {
                if (IsMoving)
                {
                    StoppedMoving?.Invoke();
                    player.ChangeState(-(int)PlayerState.Moving);
                }
                IsMoving = false;
            }
        }
Beispiel #2
0
 private void Update()
 {
     if (!IsMoving())
     {
         StoppedMoving?.Invoke(gameObject, new BallEventArgs(lastPlayer, transform.position.x));
     }
 }
Beispiel #3
0
    private void Update()
    {
        HorizontalMove = Input.GetAxis("Horizontal");
        VerticalMove   = Input.GetAxis("Vertical");

        if (HorizontalMove == 0 && VerticalMove == 0)
        {
            NotMoving?.Invoke();
            _movementController.MoveTime = 0;
            _movementController.StepTime = 0;

            if (_isPlayerMoving)
            {
                StoppedMoving?.Invoke();
                _walkController.StopMove();
                _isPlayerMoving = false;
            }

            return;
        }

        _isPlayerMoving = true;
        MovePlayer(_movementController.GetPlayerSpeed());
    }
 /// <summary>
 /// Stop the object from moving
 /// </summary>
 protected void StopMoving()
 {
     velocity = Vector2.Zero;
     IsMoving = false;
     StoppedMoving?.Invoke(this);
 }