Gyro,Cloth and Touch


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class gyro : MonoBehaviour
{
     

   Gyroscope m_Gyro;
    Quaternion gyro_rot;
 
    public static bool device_is_moved = true;
   public int idle_timer = 0;
    
     public GameObject cloth_go;    

    void Start()
    {
         m_Gyro = Input.gyro;
         m_Gyro.enabled = true;
 
    }

    // Update is called once per frame
    void Update()
    {
        GyroGet();
 
          Vector3 d = new Vector3(  m_Gyro.rotationRate.x,m_Gyro.rotationRate.y,m_Gyro.rotationRate.z  );  
        debug_go.transform.localScale = d;


        cloth_go.transform.position  = new Vector3(m_Gyro.rotationRate.y*.02f,m_Gyro.rotationRate.x*.02f,m_Gyro.rotationRate.z*.02f);

        checkForDeviceIsMoved();

       cloth_go.GetComponent<Cloth>().externalAcceleration = new Vector3( (Input.gyro.attitude.y)*-22f  ,(Input.gyro.attitude.x)*-22f,0f  );


    }



    void checkForDeviceIsMoved(){

        float motionsum = Vector3.Magnitude(m_Gyro.rotationRate);
         Debug.Log(motionsum);
        if(motionsum <.01f){
            device_is_moved = false;
            idle_timer++;
        }else{

            device_is_moved = true;
            idle_timer = 0;
        }

    }


     // The Gyroscope is right-handed.  Unity is left handed.
    // Make the necessary change to the camera.
    void  GyroGet()
    {
        gyro_rot = GyroToUnity(Input.gyro.attitude);
    }

    private static Quaternion GyroToUnity(Quaternion q)
    {
        return new Quaternion(q.x, q.y, -q.z, -q.w);
    }



     void OnGUI()
    {
        //Output the rotation rate, attitude and the enabled state of the gyroscope as a Label
        GUI.Label(new Rect(100, 300, 200, 40), "Gyro rotation rate " + m_Gyro.rotationRate);
        GUI.Label(new Rect(100, 350, 200, 40), "Gyro attitude" +  gyro_rot);
        GUI.Label(new Rect(100, 400, 200, 40), "Gyro enabled : " + m_Gyro.enabled);
    

        
    }


}

A triangulated mesh structure works visually best for cloth simulation. You can work this out with applying modifiers in Blender like Decimate and Subdivide back and forth. 🙂