You can use following code. Ofcourse this works only for the Phidget Spatial 0/0/3. Tho it should be very easy to set up othere sensors.
using System.Collections;
using Phidgets;
using Phidgets.Events;
public class phidget : MonoBehaviour {
InterfaceKit motionFloor;
// Use this for initialization
public GameObject objectToManipulate;
private Quaternion newVector;
private Spatial spatial;
public float rotationX;
public float rotationZ;
public Quaternion newQuat;
public float zSensitivity = 0.75f;
public float xSensitivity = 0.25f;
void Start () {
spatial = new Spatial();
newQuat = objectToManipulate.transform.rotation;
spatial.SpatialData += new SpatialDataEventHandler(spatial_SpatialData);
spatial.open();
spatial.waitForAttachment(1000);
spatial.DataRate = 144;
}
void Update () {
Debug.Log("RotationX = " + rotationX + " RotationZ =" + rotationZ);
newQuat.x = rotationX;
newQuat.z = rotationZ;
objectToManipulate.transform.rotation = newQuat;
}
public void spatial_SpatialData(object sender, SpatialDataEventArgs e)
{
rotationX = (float) e.spatialData[0].Acceleration[0] * xSensitivity;
rotationZ = (float) e.spatialData[0].Acceleration[1] * zSensitivity;
}
public void OnApplicationQuit ()
{
spatial.close();
}
}
Don’t use any other programs which are using the Phidget at the same time as your Unity project. The Phidget will be reserved by that program and won’t work.