private void Update()
        {
            float   horizontal = Input.GetAxis("Horizontal");
            float   vertical   = Input.GetAxis("Vertical");
            Vector3 move       = m_player.transform.forward * vertical + m_player.transform.right * horizontal;

            m_player.MoveTo(move, Mathf.Clamp01(move.magnitude));


            float      forwardChange = Input.GetAxis("LookHorizontal");
            float      angle         = m_player.MaxRotationSpeed * Mathf.Deg2Rad * forwardChange;
            float      sinAngle      = Mathf.Sin(angle / 2.0f);
            float      cosAngle      = Mathf.Cos(angle / 2.0f);
            Quaternion rotation      = new Quaternion(transform.up.x * sinAngle, transform.up.y * sinAngle, transform.up.z * sinAngle, cosAngle);
            Vector3    newForward    = rotation * transform.forward;

            m_player.RotateToward(newForward, Mathf.Abs(forwardChange));

            float angleChange = Input.GetAxis("LookVertical") * VerticalSensibility;

            m_cameraControl.TargetAngle += angleChange;

            if (Input.GetButton("Jump"))
            {
                m_player.Jump();
            }

            if (m_carry.IsCarrying())
            {
                if (Input.GetButtonDown("Carry"))
                {
                    m_carry.Release();
                }
                if (Input.GetButtonDown("Interact"))
                {
                    m_carry.Shoot();
                }
            }
            else
            {
                if (Input.GetButtonDown("Carry"))
                {
                    m_carry.Carry();
                }

                if (Input.GetButtonDown("Interact"))
                {
                    m_interactor.Interact();
                }
            }
        }
예제 #2
0
    private void Update()
    {
        if (m_player == null)
        {
            Setup();
        }

        else if (isLocalPlayer)
        {
            bool jumped, carry, interact;

            float   horizontal   = Input.GetAxis("Horizontal");
            float   vertical     = Input.GetAxis("Vertical");
            Vector3 newDirection = m_player.transform.forward * vertical + m_player.transform.right * horizontal;
            m_player.MoveTo(newDirection, Mathf.Clamp01(newDirection.magnitude));

            float      forwardChange = Input.GetAxis("LookHorizontal");
            float      angle         = m_player.MaxRotationSpeed * Mathf.Deg2Rad * forwardChange;
            float      sinAngle      = Mathf.Sin(angle / 2.0f);
            float      cosAngle      = Mathf.Cos(angle / 2.0f);
            Quaternion rotation      = new Quaternion(m_player.transform.up.x * sinAngle, m_player.transform.up.y * sinAngle, m_player.transform.up.z * sinAngle, cosAngle);
            Vector3    newForward    = rotation * m_player.transform.forward;
            m_player.RotateToward(newForward, Mathf.Abs(forwardChange));

            float newAngle = m_cameraControl.TargetAngle + Input.GetAxis("LookVertical") * VerticalSensibility;
            m_cameraControl.TargetAngle = newAngle;

            if (jumped = Input.GetButton("Jump"))
            {
                m_player.Jump();
            }

            if (m_carry.IsCarrying())
            {
                if (carry = Input.GetButtonDown("Carry"))
                {
                    m_carry.Release();
                }
                if (interact = Input.GetButtonDown("Interact"))
                {
                    m_carry.Shoot();
                }
            }
            else
            {
                if (carry = Input.GetButtonDown("Carry"))
                {
                    m_carry.Carry();
                }

                if (interact = Input.GetButtonDown("Interact"))
                {
                    m_interactor.Interact();
                }
            }

            // sync
            if (isServer)
            {
                r_direction = newDirection;
                r_forward   = new Vector4(newForward.x, newForward.y, newForward.z, forwardChange);
                r_carry     = carry;
                r_jump      = jumped;
                r_interact  = interact;
                r_angle     = newAngle;
            }
            else
            {
                CmdSendData(newDirection,
                            new Vector4(newForward.x, newForward.y, newForward.z, forwardChange),
                            carry, jumped, interact, newAngle);
            }
        }
    }