Exemplo n.º 1
0
    private void AttackInputCallback(InputAction.CallbackContext ctx)
    {
        ButtonControl button = ctx.control as ButtonControl;

        if (!button.wasPressedThisFrame)
        {
            return;
        }

        if (m_PlayerStance == null)
        {
            return;
        }

        if (!m_PlayerStance.IsCombatStance())
        {
            AudioManager.m_Instance.PlaySoundAtPosition("GEN_Weapon_Draw", transform.position);
            m_PlayerStance.SetStance(PlayerStance.Stance.STANCE_TWOHANDED);
            return;
        }

        if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_ATTACK))
        {
            return;
        }

        m_AttackedInCurrentFrame = true;
    }
Exemplo n.º 2
0
    private void ComputeXZAxisVelocity()
    {
        // If the player is not allowed to walk, don't.
        if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_WALK))
        {
            m_MovementParams.m_Velocity.x = Mathf.Lerp(m_MovementParams.m_Velocity.x, 0, Time.deltaTime * 5);
            m_MovementParams.m_Velocity.z = Mathf.Lerp(m_MovementParams.m_Velocity.z, 0, Time.deltaTime * 5);
            return;
        }

        Vector2 inputXZ = GetInputAxis();

        // This is to fix not being able to walk forward when the camera is looking down
        Vector3 cameraForward = Camera.main.transform.forward;

        cameraForward.y = 0;
        cameraForward.Normalize();

        Vector3 xzVelocity = Camera.main.transform.right * inputXZ[0] + cameraForward * inputXZ[1];

        xzVelocity  *= m_MovementParams.m_MoveSpeed;
        xzVelocity.y = 0;

        // Slow the player down when walking backwards or side to side
        if (m_PlayerStance.IsCombatStance() && !IsMovingForward())
        {
            xzVelocity *= m_MovementParams.m_NonForwardMovePenalty.Evaluate(Mathf.Abs(VelocityDotForward()));
        }

        // Slow the player down when blocking
        if (m_PlayerCombatHandler.IsBlocking())
        {
            xzVelocity *= (1 - m_MovementParams.m_BlockMovePenalty);
        }

        // Add external modifier;
        xzVelocity.Scale(m_MovementParams.m_ExternalVelocityModifier);

        // Update movement params so other system can use this final value.
        m_MovementParams.m_Velocity.x = xzVelocity.x;
        m_MovementParams.m_Velocity.z = xzVelocity.z;
    }
Exemplo n.º 3
0
    void Update()
    {
        m_AxisDelta.x = Mathf.Clamp(Mathf.Lerp(m_AxisDelta.x, 0, Time.deltaTime * 5), -1, 1);
        m_AxisDelta.y = Mathf.Clamp(Mathf.Lerp(m_AxisDelta.y, 0, Time.deltaTime * 5), -1, 1);

        Vector2 playerInput = m_PlayerMovement.GetInputAxis();

        m_AxisDelta.x = Mathf.Abs(m_AxisDelta.x) < Mathf.Abs(playerInput.x) ? playerInput.x : m_AxisDelta.x;
        m_AxisDelta.y = Mathf.Abs(m_AxisDelta.y) < Mathf.Abs(playerInput.y) ? playerInput.y : m_AxisDelta.y;

        m_Animator.SetFloat("Velocity-XZ-Normalized-01", m_AxisDelta.magnitude);

        // TODO: Support Velocity X, Velocity Z for unarmed rotation
        if (m_PlayerStance != null && m_PlayerStance.IsCombatStance())
        {
            m_Animator.SetFloat("Velocity-X-Normalized", m_AxisDelta.x);
            m_Animator.SetFloat("Velocity-Z-Normalized", m_AxisDelta.y);
        }

        Vector3 velocity = m_PlayerMovement.GetVelocity();

        m_Animator.SetFloat("Velocity-Y-Normalized", velocity.y);

        bool isGrounded = m_PlayerMovement.IsGrounded();

        // Set Grounded boolean
        m_Animator.SetBool("Grounded", isGrounded);

        // Set Player Weapon Stance
        if (m_PlayerStance != null)
        {
            m_Animator.SetInteger("WeaponIndex", (int)m_PlayerStance.GetStance());
        }

        // Set Jump trigger
        bool hasJumped = m_PlayerMovement.JumpedInCurrentFrame();

        if (hasJumped)
        {
            m_Animator.SetTrigger("Jump");
        }

        // Set combat states
        HandleCombatAnimations();

        // Set skill states
        HandleSkillAnimations();
    }