- Home /
Question by
Pablethe · Aug 19, 2017 at 07:47 AM ·
playerprefsaccelerometermatrix4x4input.accelerationmatrix4x4.trs
Save Matrix 4x4?
Hi Guys!
I need help as fast as possible. I tell them that I am developing a game with an accelerometer. And the subject of calibration, it is going crazy. I give them the Script of movement that I am using:
//Method for calibration
public void calibrateAccelerometer()
{
wantedDeadZone = Input.acceleration;
Quaternion rotateQuaternion = Quaternion.FromToRotation(new Vector3(0f, 0f, -1f), wantedDeadZone);
//create identity matrix ... rotate our matrix to match up with down vec
Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, rotateQuaternion, new Vector3(1f, 1f, 1f));
//get the inverse of the matrix
calibrationMatrix = matrix.inverse;
}
//Method to get the calibrated input
Vector3 getAccelerometer(Vector3 accelerator){
Vector3 accel = this.calibrationMatrix.MultiplyVector(accelerator);
return accel;
}
//Finally how you get the accelerometer input
Vector3 _InputDir;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
_InputDir = getAccelerometer(Input.acceleration);
//then in your code you use _InputDir instead of Input.acceleration for example
//transform.Translate (_InputDir.x, 0, -_InputDir.z);
MovimientoAcelerometro ();
}
Simple, need save CalibrationMatrix (Matrix4x4) WITH A BUTTON AND LOAD AUTOCALLY IN VOID START ALLWAYS PREVIOUSLY SAVED.
CAN SAVE MATRIX4x4 WITH PLAYERPREFS??? NEED HELP.
THANKS YOU FOREVER! Sorry for my english =D
Comment