Ejemplo n.º 1
0
    private void HandleCombatAnimations()
    {
        if (m_PlayerCombatHandler == null)
        {
            return;
        }

        if (m_PlayerCombatHandler.GetAttackedInCurrentFrame())
        {
            m_Animator.SetTrigger("Attack");
            return;
        }

        if (m_PlayerMovement.DodgedBackwardsInCurrentFrame())
        {
            m_Animator.SetTrigger("Backstep");
            return;
        }

        if (m_PlayerMovement.DodgedInCurrentFrame())
        {
            m_Animator.SetTrigger("Roll");
            return;
        }

        m_Animator.SetBool("Block", m_PlayerCombatHandler.IsBlocking());
    }
Ejemplo 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;
    }
Ejemplo n.º 3
0
    void SetCurrentActions()
    {
        m_CurrentActions = Action.ACTION_UNSET;

        if (m_PlayerMovement.GetXZVelocity().magnitude > 0)
        {
            m_CurrentActions |= Action.ACTION_WALK;
        }

        // TODO: Set Sprint action

        // TODO: Shift Bool Checks into Player

        if (m_PlayerMovement.IsFrozen())
        {
            m_CurrentActions = Action.ACTION_FROZEN;
        }

        if (m_PlayerMovement.IsDead())
        {
            m_CurrentActions = Action.ACTION_DEAD;
        }

        if (m_PlayerMovement.IsDamaged())
        {
            m_CurrentActions = Action.ACTION_DAMAGED;
        }

        if (m_PlayerMovement.GetVelocity().y > 0 || !m_PlayerMovement.IsGrounded())
        {
            m_CurrentActions |= Action.ACTION_JUMP;
        }

        if (m_PlayerMovement.IsDodging())
        {
            m_CurrentActions |= Action.ACTION_DODGE;
        }

        if (m_PlayerMovement.IsDodging() && m_PlayerMovement.IsDodgingBackwards())
        {
            m_CurrentActions |= Action.ACTION_DODGEBACK;
        }

        if (m_PlayerAnimation.IsPlayingAttackAnimation())
        {
            m_CurrentActions |= Action.ACTION_ATTACK;
        }

        if (m_PlayerAnimation.IsPlayingCastingAnimation())
        {
            m_CurrentActions |= Action.ACTION_CASTSPELL;
        }

        if (m_PlayerCombatHandler.IsBlocking())
        {
            m_CurrentActions |= Action.ACTION_BLOCK;
        }

        if (m_IsTogglingCombatStance)
        {
            m_CurrentActions |= Action.ACTION_SHEATHE;
        }

        if (m_CurrentActions == Action.ACTION_UNSET)
        {
            m_CurrentActions = Action.ACTION_IDLE;
        }
    }
Ejemplo n.º 4
0
    private void Update()
    {
        if (m_PlayerNetworkObject == null)
        {
            return;
        }

        if (m_PlayerNetworkObject.IsOwner)
        {
            if (m_PlayerMovement == null || m_PlayerAnimation == null || m_HealthHandler == null || m_PlayerStance == null)
            {
                Debug.LogWarning("Movement/Animation/Health/Stance script not found on local player");
                return;
            }

            // Send movement state
            m_PlayerNetworkObject.position = transform.position;
            m_PlayerNetworkObject.rotation = transform.rotation;

            // Send animation state
            m_PlayerNetworkObject.axisDelta    = m_PlayerMovement.GetInputAxis();
            m_PlayerNetworkObject.vertVelocity = m_PlayerMovement.GetVelocity().y;
            m_PlayerNetworkObject.grounded     = m_PlayerMovement.IsGrounded();

            // Combat states
            m_PlayerNetworkObject.weaponIndex = (int)m_PlayerStance.GetStance();
            m_PlayerNetworkObject.blocked     = m_PlayerCombatHandler.IsBlocking();
            m_PlayerNetworkObject.skillIndex  = m_SkillHandler.GetCurrentActiveSkill();

            // Fun misc
            if (m_PlayerAnimationLookat != null)
            {
                m_PlayerNetworkObject.lookatDir = m_PlayerAnimationLookat.GetLookatDirection();
            }

            if (m_PlayerCombatHandler.GetAttackedInCurrentFrame())
            {
                Debug.Assert(m_PlayerNetworkObject.weaponIndex != 0, "Attacking unarmed, wtf?");
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_ATTACK, Receivers.All);
            }

            if (m_PlayerMovement.DodgedBackwardsInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_BACK_DASH, Receivers.All);
            }
            else if (m_PlayerMovement.DodgedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_DASH, Receivers.All);
            }


            if (m_PlayerMovement.JumpedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_JUMP, Receivers.All);
            }

            // Send health state
            if (m_HealthHandler.DamagedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_DAMAGED, Receivers.All);
            }
        }
        else
        {
            // Receive movement state
            transform.position = m_PlayerNetworkObject.position;
            transform.rotation = m_PlayerNetworkObject.rotation;

            // Receive animation state
            if (m_Animator == null)
            {
                Debug.LogWarning("Animator does not exist on player");
                return;
            }
            m_Animator.SetFloat("Velocity-XZ-Normalized-01", m_PlayerNetworkObject.axisDelta.magnitude);
            m_Animator.SetFloat("Velocity-X-Normalized", m_PlayerNetworkObject.axisDelta.x);
            m_Animator.SetFloat("Velocity-Z-Normalized", m_PlayerNetworkObject.axisDelta.y);
            m_Animator.SetFloat("Velocity-Y-Normalized", m_PlayerNetworkObject.vertVelocity);
            m_Animator.SetBool("Grounded", m_PlayerNetworkObject.grounded);
            m_Animator.SetInteger("WeaponIndex", m_PlayerNetworkObject.weaponIndex);
            m_Animator.SetBool("Block", m_PlayerNetworkObject.blocked);
            m_Animator.SetInteger("SkillsIndex", m_PlayerNetworkObject.skillIndex);

            // Show and hide sword
            // TODO: add delay or make it work with animation callbacks
            m_Player.SetWeaponActive(m_PlayerNetworkObject.weaponIndex != 0);

            // Misc
            if (m_PlayerAnimationLookat != null)
            {
                m_PlayerAnimationLookat?.SetLookatDirection(m_PlayerNetworkObject.lookatDir);
                m_PlayerAnimationLookat?.SetLookatType(PlayerAnimationLookat.LookAtType.LOOKAT_NETWORKED);
            }
        }
    }