Hello everyone, I need a bit of help
I got a camera in my scene as a child of a gameobject. I need the camera to rotate smoothly around its parent depending on the gyroscope.
Kinda like filming a box while turning around it.
I have the script to rotate with the gyro on the parent object, but it work strangely because after a few turns the camera start going sideways and weird.
Also, if try to turn more than 180, the camera flip around, like the orientation is changing, except it’s not.
Anyone know a solution?
using UnityEngine;
using System.Collections;
public class GyroCam : MonoBehaviour {
private Quaternion initialRotation;
private Quaternion gyroInitialRotation;
void Start ()
{
Input.gyro.enabled = true;
initialRotation = transform.rotation;
//gyroInitialRotation = Input.gyro.attitude;
}
void Update ()
{
//smooth gyro rotation
float newPositionx = Mathf.SmoothDamp(transform.position.x, Input.gyro.rotationRateUnbiased.x, ref _velocity, damp_speed);
float newPositiony = Mathf.SmoothDamp(transform.position.y, Input.gyro.rotationRateUnbiased.y, ref _velocity, damp_speed);
//rotate
transform.Rotate (newPositionx, 0, newPositiony);
}
}