Пример #1
0
    private void Update()
    {
        if (!m_Character.CanMove() || pauseInterface.Paused)
        {
            return;
        }

#if !MOBILE_INPUT
        // check for shift press to run
        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            runLock = !runLock;
        }
#endif

        if (!m_Jump)
        {
            m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
        }
    }
Пример #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!m_Character.CanCollide())
        {
            return;
        }

        Vector3 m_Move = Vector3.zero;

        //calculate inputs
        float v = 0;
        float h = 0;

        //determine where to turn towards/move towards
        if (walkPoints.Count > 0)
        {
            Vector3 dest = walkPoints.Peek().transform.position;

            //we are looking in transform.forward, change to dest - transform.position
            Vector3 dir = dest - transform.position;
            dir.y = 0;
            Quaternion dirQ = Quaternion.LookRotation(dir, Vector3.up);

            FixRotation(dir, dirQ, ref v, ref h);
        }
        //Finish path staring in direction endingDir
        else if (endingDir != Vector3.zero)
        {
            Quaternion dirQ = Quaternion.LookRotation(endingDir, Vector3.up);
            if (Vector3.Angle(transform.forward, endingDir) > rotError)
            {
                FixRotation(endingDir, dirQ, ref v, ref h);
            }
            else
            {
                endingDir = Vector3.zero;
            }
        }
        //After character has completed route, if idle action exists, perform action
        else if (queuedAction != "")
        {
            m_Character.SetIdleAction(queuedAction, queuedValue);
            queuedAction = "";
        }

        // calculate move direction to pass to character
        if (m_Character.CanMove())
        {
            v *= runSpeed;

            // we use local-relative directions in the case of no main camera
            m_Move = v * transform.forward;
        }
        else
        {
            v = 0;
        }

        //impart gravity continuously
        m_Move += new Vector3(0, -20f, 0);

        // pass all parameters to character controller
        m_Character.cControl.Move(m_Move * Time.fixedDeltaTime);

        //make animation changes
        m_Character.UpdateAnimator(m_Move, v, h * turnSpeed, false);
    }