Пример #1
0
        // Fixed update is called in sync with physics
        private void FixedUpdate()
        {
            // read inputs if not using move
            float v = 0, h = 0;

            if ((!CC || CC.CanMove()) && CanMove)
            {
                h = InputManager.GetAxis("Horizontal");
                v = InputManager.GetAxis("Vertical");
            }

            if ((targeter && !targeter.cameraSnapped) || !targeter) //Normal third person move
            {
                // calculate camera relative direction to move:
                m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
                m_Move       = v * m_CamForward + h * m_Cam.right;
                m_Character.Move(m_Move);                  // pass all parameters to the character control script
            }
            else if (targeter && targeter.CurrentTarget()) //Strafe
            {
                var vec = targeter.CurrentTarget().transform.position - transform.position;
                //Don't move if we're not facing
                if (Vector3.Dot(vec.normalized, transform.forward) > 0.7f)
                {
                    m_Character.Strafe(h, v); //Strafe
                }
                //Face target
                var rot = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(vec.normalized), 0.1f).eulerAngles;
                rot.x = 0;
                rot.z = 0;
                transform.rotation = Quaternion.Euler(rot);
            }
        }