Добрый день.Я изо всех сил пытаюсь выяснить, почему моя камера остается с ног на голову.Все работает, камера поворачивается во всех направлениях, как задумано, но просто вверх ногами, и я не могу понять почему.Может быть, кто-то может указать мне правильное направление.
public float rotationSpeed = 8f;
Vector3 acceleration = Vector3.zero;
float heading = 0f;
void Start()
{
Input.compass.enabled = true;
Input.location.Start();
}
void Update()
{
SetAcceleration();
SetCompassHeading();
transform.eulerAngles = SetRotation();
}
void SetAcceleration()
{
Vector3 _acceleration = Input.acceleration;
acceleration.x = Mathf.Lerp(acceleration.x, _acceleration.x, Time.deltaTime * rotationSpeed);
acceleration.y = Mathf.Lerp(acceleration.y, _acceleration.y, Time.deltaTime * rotationSpeed);
acceleration.z = Mathf.Lerp(acceleration.z, _acceleration.z, Time.deltaTime * rotationSpeed);
}
void SetCompassHeading()
{
float _heading = Input.compass.trueHeading;
heading = Mathf.LerpAngle(heading, _heading, Time.deltaTime * rotationSpeed);
}
Vector3 SetRotation()
{
float _rotationX = Mathf.Atan2(acceleration.z, acceleration.y);
float _magnitudeYZ = Mathf.Sqrt(Mathf.Pow(acceleration.y, 2) + Mathf.Pow(acceleration.z, 2));
float _rotationZ = Mathf.Atan2(acceleration.x, _magnitudeYZ);
float _angleX = _rotationX * (180f / Mathf.PI)+11;
float _angleZ = -_rotationZ * (180f / Mathf.PI);
return new Vector3(_angleX, -(_angleZ - heading), 0f);
}