예제 #1
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();
    }
예제 #2
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);
            }
        }
    }