Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        // Measure movement since last frame
        Vector2 deltaPos           = (Vector2)transform.position - previousPosition;
        float   horizontalDeltaPos = Mathf.Abs(deltaPos.x);

        OnPlayerMovement?.Invoke(horizontalDeltaPos);
        previousPosition = transform.position;

        // Move player
        controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
        jump = false;
    }
Ejemplo n.º 2
0
        private void SetAnimatorValues()
        {
            _movement.x = Input.GetAxisRaw("Horizontal");
            _movement.y = Input.GetAxisRaw("Vertical");

            if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
            {
                _lastMovement = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
                OnPlayerMovement?.Invoke(true);
            }
            if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
            {
                _lastMovement = new Vector2(0f, Input.GetAxisRaw("Vertical"));
                OnPlayerMovement?.Invoke(true);
            }

            animator.SetFloat(Speed, _movement.sqrMagnitude);
            animator.SetFloat(Horizontal, _movement.x);
            animator.SetFloat(Vertical, _movement.y);
            animator.SetFloat(LastHorizontal, _lastMovement.x);
            animator.SetFloat(LastVertical, _lastMovement.y);
        }