I am trying to move an object based on acceleration and angle values by reading the same from a CSV file. The script i wrote shows no error but the object is not moving. What should i add to move the object?
private Rigidbody rigid;
float smooth = 5.0f;
void Start()
{
rigid = GetComponent<Rigidbody>();
StartCoroutine(MyCoroutine());
}
IEnumerator MyCoroutine()
{
TextAsset Sensor = Resources.Load<TextAsset>("Sensor");
string[] data = Sensor.text.Split(new char[] { '\n' });
for (int i = 1; i < data.Length - 1; i++)
{
string[] row = data[i].Split(new char[] { ',' });
Data q = new Data();
float.TryParse(row[0], out q.accx);
float.TryParse(row[1], out q.accy);
float.TryParse(row[2], out q.accz);
float.TryParse(row[3], out q.gyrox);
float.TryParse(row[4], out q.gyroy);
float.TryParse(row[5], out q.gyroz);
Quaternion target = Quaternion.Euler(q.gyrox, q.gyroy, q.gyroz);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
if (q.accx == 0 && q.accy == 0 && q.accz == 0)
{
rigid.velocity = Vector3.zero;
}
else
{
rigid.AddForce(q.accx * Time.deltaTime, q.accy * Time.deltaTime, q.accz * Time.deltaTime, ForceMode.Acceleration);
}
yield return new WaitForSeconds(1);
}
}