Acceleration and accelerometer calibration
In my game I move a sphere using the accelerometer. I calibrate it with the matrix4x4 method I saw in another thread (link: http://answers.unity3d.com/questions/927515/accelerometer-calibration-2.html)
I need something similar but it must work only in x and z axis. So I tried to edit it and this is the result.
void Calibrate()
{
Vector3 wantedDeadZone = new Vector3(Input.acceleration.x, 0, Input.acceleration.y);
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;
}
//returns the "calibrated" acceleration
Vector3 getAccelerometer(Vector3 accelerator)
{
Vector3 accel = calibrationMatrix.MultiplyVector(accelerator);
return accel;
}
void FixedUpdate()
{
Vector3 rawAccel = new Vector3(Input.acceleration.x * speed, 0, Input.acceleration.y * speed);
Vector3 movement = getAccelerometer(rawAccel);
rb.AddForce(movement);
}
The calibration works great on the y axis but it doesnt't work on the x axis. The "calibrated" acceleration on the x axis is 0 when the phone is on flat, like on a table.
How can I fix this problem?
Thanks in advance and sorry for my bad English
Your answer
Follow this Question
Related Questions
Slerp ignoring time component? 1 Answer
Clamp vector values to a minimum circular radius around player? 1 Answer
iron sight using inverse kinematic 0 Answers
Grappling hook physics script error 0 Answers
Rotate object towards Vector 0 Answers