I want to make it so that the gyroscope will only change the x and y-axes of an object. There is code for one axis and for three axes (mostly used), but I couldn't find anything about two axis and wasn't able to do it myself.
Asked
Active
Viewed 127 times
-1
-
1Please provide enough code so others can better understand or reproduce the problem. – Community Oct 26 '21 at 16:35
1 Answers
1
Reset the z-axis or whatever axis before applying-
private Vector3 startEulerAngles;
private Vector3 startGyroAttitudeToEuler;
private void Start()
{
Input.gyro.enabled = true;
startEulerAngles = transform.eulerAngles;
startGyroAttitudeToEuler = Input.gyro.attitude.eulerAngles;
}
private void Update()
{
Vector3 deltaEulerAngles = Input.gyro.attitude.eulerAngles - startGyroAttitudeToEuler;
// Z-axis reset, so it won't be applied.
deltaEulerAngles.z = 0.0f;
transform.eulerAngles = startEulerAngles - deltaEulerAngles;
}

Peter Mortensen
- 30,738
- 21
- 105
- 131

Srejon Khan
- 438
- 2
- 8
-
thanks a lot man! i really appreciate your answer! I will go ahead and apply this into my code. this looks like a very good idea and looks like it will work – YGreater Oct 27 '21 at 12:04