コード例 #1
0
    private void FixedUpdate()
    {
        if (mecanim == null)
        {
            mecanim = GetComponentInChildren <MecanimWrapper>();
        }

        Collider[] overlapColliders = Physics.OverlapSphere(transform.localPosition, groundCheckRadius, noPlayerLayerMask);
        isGrounded = overlapColliders.Length != 0 ? true : false;

        if (LeftJoystick != null && (photonView.IsMine || !PhotonNetwork.IsConnectedAndReady))
        {
            Hinput = Mathf.Clamp(LeftJoystick.input.x + Input.GetAxis("Horizontal"), -1, 1);
            Vinput = Mathf.Clamp(LeftJoystick.input.y + Input.GetAxis("Vertical"), -1, 1);

            if (JumpButton != null)
            {
                m_Jump = (Input.GetKeyDown(KeyCode.Space) || JumpButton.Pressed);
            }

            camera.MoveTo(TouchField.TouchDist.y * cameraYSpeed * Time.fixedDeltaTime * -1);

            cameraRotation     = new Vector3((transform.forward * 5 + transform.position).x, (transform.forward * 5 + transform.position).y + (camera.transform.forward * 5).y, (transform.forward * 5 + transform.position).z) + Vector3.up;
            transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + Vector3.up * TouchField.TouchDist.x * rotateSpeed * Time.fixedDeltaTime);
        }
        else if (newPosition != Vector3.zero)
        {
            Hinput     = Mathf.Lerp(Hinput, newHinput, Time.fixedDeltaTime * learpSpeedf);
            Vinput     = Mathf.Lerp(Vinput, newVinput, Time.fixedDeltaTime * learpSpeedf);
            targetJump = Mathf.Lerp(targetJump, newTargetJump, Time.fixedDeltaTime * learpSpeedf);

            if (Vector3.Distance(transform.position, newPosition) > distanceToForceTP)
            {
                transform.position = Vector3.Lerp(transform.position, newPosition, Time.fixedDeltaTime * learpSpeedf);
            }
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(newRotation), Time.fixedDeltaTime * learpSpeedf);
        }
        if (isGrounded && mecanim != null)
        {
            // calculate camera relative direction to move:
            m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
            m_Move       = Vinput * transform.forward + Hinput * transform.right;
            mecanim.SetHorizontalSpeed(Hinput);
            mecanim.SetVerticalSpeed(Vinput);
            mecanim.SetJump(false);
            targetJump = -1f;
        }
        else
        {
/*            mecanim.SetHorizontalSpeed(0);
 *          mecanim.SetVerticalSpeed(0);*/
            mecanim.SetJump(true);
        }

        if (m_Move != Vector3.zero)
        {
            m_Move -= m_Move * Time.fixedDeltaTime;
        }



        Jump();

        /*mecanim.SetJump(targetJump);*/

        // pass all parameters to the character control script
        _characterController.Move(m_Move * Time.fixedDeltaTime * speed);
        m_Jump = false;
    }
コード例 #2
0
 // Update is called once per frame
 void Update()
 {
     mecanimWrapper.SetVerticalSpeed(0);
     mecanimWrapper.SetHorizontalSpeed(0);
 }