void Update()
    {
        if (m_Animator && Camera.main)
        {
            Vector3 worldDir;
            float   horizontal = Input.GetAxis("Horizontal");
            float   vertical   = Input.GetAxis("Vertical");
            Vector3 dir        = new Vector3(horizontal, 0, vertical);
            worldDir   = Camera.main.transform.rotation * dir; // Converts joystick input in Worldspace coordinates
            worldDir.y = 0;                                    // Kill Z
            worldDir.Normalize();

            float speed     = Mathf.Clamp(worldDir.magnitude, 0, 1);
            float direction = 0.0f;
            if (speed > 0.01f)             // dead zone
            {
                Vector3 axis = Vector3.Cross(transform.forward, worldDir);
                direction = Vector3.Angle(transform.forward, worldDir) / 180.0f * (axis.y < 0 ? -1 : 1);
            }
            m_Speed     = speed;
            m_Direction = direction;
            //JoystickToWorld.ComputeSpeedDirection(transform,ref m_Speed, ref m_Direction);
        }

        m_Locomotion.Do(m_Speed * 6, m_Direction * 180);
        m_Animator.SetBool("HoldLog", hasLog);
    }
Beispiel #2
0
 protected void SetupAgentLocomotion()
 {
     if (AgentDone())
     {
         locomotion.Do(0, 0);
         if (particleClone != null)
         {
             GameObject.Destroy(particleClone);
             particleClone = null;
         }
     }
     else
     {
         float   speed    = agent.desiredVelocity.magnitude;
         Vector3 velocity = Quaternion.Inverse(transform.rotation) * agent.desiredVelocity;
         float   angle    = Mathf.Atan2(velocity.x, velocity.z) * Mathf.Rad2Deg;
         locomotion.Do(speed, angle);
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (m_Animator && Camera.main)
     {
         Vector3 worldDir;
         float   horizontal = Input.GetAxis("Horizontal");
         float   vertical   = Input.GetAxis("Vertical");
         Vector3 dir        = new Vector3(horizontal, 0, vertical);
         worldDir   = Camera.main.transform.rotation * dir;
         worldDir.y = 0;
         worldDir.Normalize();
         float speed     = Mathf.Clamp(worldDir.magnitude, 0, 1);
         float direction = 0.0f;
         if (speed > 0.01f)
         {
             Vector3 axis = Vector3.Cross(transform.forward, worldDir);
             direction = Vector3.Angle(transform.forward, worldDir) / 180.0f * (axis.y < 0 ? -1 : 1);
         }
         m_Speed     = speed;
         m_Direction = direction;
     }
     m_Locomotion.Do(m_Speed * 6, m_Direction * 180);
     m_Animator.SetBool("HoldLog", hasLog);
 }