Hello! I started playing with the accelerometer, and there’s a problem.
When the camera is rotated with an accelerometer, vibrations (camera shake) occur when the motion is attenuated, and then continue at rest.
If the sensitivity is 1, then there is no vibration, everything is smooth.
Camera following speed is slow, not realistic.
If the sensitivity is> 1, there is vibration.
The more sensitivity, the more realistic the movement, but more vibrations.
I try in several ways, but the behavior is the same.
The gyroscope is not interested.
Task
Remove vibrations (vibrations), increasing sensitivity.
Camera movement
Orientation: Landscape.
Tilting the phone away from myself or toward myself turns the camera in the game up or down.
Tilting the phone to the left or right rotates the camera about the Z axis (while retaining the feeling that the ground in the game is always parallel to the floor in your room).
using UnityEngine;
using System.Collections;
public class AccelerometerCameraControl : MonoBehaviour
{
public float sensitivityXZ = 9f;
private float rotationalAngleFactorXZ = -90f;
private Vector3 currentRotationXZ;
void LateUpdate ()
{
Way2();
}
// Quaternion.Slerp
public void Way2()
{
currentRotationXZ.x = Input.acceleration.z * rotationalAngleFactorXZ;
currentRotationXZ.z = Input.acceleration.x * rotationalAngleFactorXZ;
transform.localRotation = Quaternion.Slerp(
transform.localRotation,
Quaternion.Euler(currentRotationXZ),
Time.deltaTime * sensitivityXZ);
}
// Math.Lerp
public void Way1()
{
currentRotationXZ.y = transform.localEulerAngles.y;
currentRotationXZ.x = Mathf.LerpAngle(
transform.localEulerAngles.x,
Input.acceleration.z * rotationalAngleFactorXZ,
sensitivityXZ * Time.deltaTime);
currentRotationXZ.z = Mathf.LerpAngle(
transform.localEulerAngles.z,
Input.acceleration.x * rotationalAngleFactorXZ,
sensitivityXZ * Time.deltaTime);
transform.localRotation = Quaternion.Euler(currentRotationXZ);
}
}


