Exemple #1
0
    //
    void Move()
    {
        Vector3 direction = _targetPositionVector;

        direction.y = 0f;

        if (InPlace)
        {
            Vector3 v1 = transform.forward;
            //v1.y = 0f;
            Vector3 v2 = _targetTransform.forward;
            //v2.y = 0f;

            float   angle = Vector3.Angle(v2, v1);
            Vector3 cross = Vector3.Cross(v2, v1);
            if (cross.y < 0)
            {
                angle = -angle;
            }

            if (angle < 2f)
            {
                angle = 0f;
            }

            angle = angle / 180f;
            _character.Move(new Vector3(-angle, 0f, 0f), false);
        }
        else
        {
            direction /= 4f;
            _character.Move(direction, true);
        }
    }
Exemple #2
0
    // Fixed update is called in sync with physics
    private void FixedUpdate()
    {
        // read inputs
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        // calculate move direction to pass to character
        if (m_Cam != null)
        {
            // calculate camera relative direction to move:
            m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 1, 1)).normalized;
            m_Move       = v * m_CamForward + h * m_Cam.right;
        }
        else
        {
            // we use world-relative directions in the case of no main camera
            m_Move = v * Vector3.forward + h * Vector3.right;
        }
        mydrago.Move(m_Move, true);
    }