Unity-Gyroscope-Parallax icon indicating copy to clipboard operation
Unity-Gyroscope-Parallax copied to clipboard

Resolve "Gimbal Lock" problem by using Quaternion for rotation

Open craftercis opened this issue 1 year ago • 9 comments
trafficstars

I love this tool!

Just a quick question: In the first screenshot, that's how I want it to start when the user holds the phone vertically. Currently, it starts like in the second screenshot. When I place my mobile on a table, it looks like the first screenshot. Do you know how I can fix this?

If I have a Gyro rotator and a rotator attitude on this cube with a max offset of 30 on the Y. My phone starts at -30. I want this to be 0

Screenshot1 Screenshot2

craftercis avatar Jan 21 '24 15:01 craftercis

Hey @craftercis , glad to hear you love it.

If I have a Gyro rotator and a rotator attitude on this cube with a max offset of 30 on the Y. My phone starts at -30. I want this to be 0

Please avoid having more than one Gyro...2D on a single gameObject because they fight each other. You better make wrapper parent gameObject to keep the second Gyro...2D on it.

Just a quick question: In the first screenshot, that's how I want it to start when the user holds the phone vertically. Currently, it starts like in the second screenshot. When I place my mobile on a table, it looks like the first screenshot. Do you know how I can fix this?

Disable / Enable Gyro...2D component to reset the original value. If you need to, you may change Cube position/rotation when Gyro component is disabled, then enable it. The new value will be used as Origin.

IvanMurzak avatar Jan 21 '24 19:01 IvanMurzak

Please avoid having more than one Gyro...2D on a single gameObject because they fight each other. You better make wrapper parent gameObject to keep the second Gyro...2D on it.

Ah then I was confused by your screenshots haha.

Disable / Enable Gyro...2D component to reset the original value. If you need to, you may change Cube position/rotation when Gyro component is disabled, then enable it. The new value will be used as Origin.

So I should disable them at start, and when the gyroscope is fully loaded I would enable them again?

craftercis avatar Jan 21 '24 19:01 craftercis

What I want is the position of screenshot 1 (that's when it's lying on my table) when you hold the phone in your hands Edit: I have tried disabling and enabling gyro... and setting a new rotation for the cueb but he is always going to the rotation at screenshot 2. I think there should be a change in the code. This thread is what I mean:

https://gamedev.stackexchange.com/questions/174107/unity-gyroscope-orientation-attitude-wrong

Edit 2: Your demo scene has the same problem

craftercis avatar Jan 21 '24 20:01 craftercis

Please avoid having more than one Gyro...2D on a single gameObject because they fight each other. You better make wrapper parent gameObject to keep the second Gyro...2D on it.

Ah then I was confused by your screenshots haha.

Disable / Enable Gyro...2D component to reset the original value. If you need to, you may change Cube position/rotation when Gyro component is disabled, then enable it. The new value will be used as Origin.

So I should disable them at start, and when the gyroscope is fully loaded I would enable them again?

I believe you want to have just a single GyroRotator2DGravity on a single gameObject. Also, you don't need to disable/enable in case when you don't want to change the Origin position in runtime.

When the Gyro... component gets OnEnable it stores the current gyroscope and current gameObject transform as Origin value. Then any next data changes in the gyroscope inputs start to impact on rotation/position of a gameObject.

If you want to change standard behavior. For example, change the Origin data for a gyroscope somewhere in the middle of your app/game execution. You will need to Disable/Enable the Gyro... component to reset the data.

IvanMurzak avatar Jan 21 '24 22:01 IvanMurzak

What I want is the position of screenshot 1 (that's when it's lying on my table) when you hold the phone in your hands Edit: I have tried disabling and enabling gyro... and setting a new rotation for the cueb but he is always going to the rotation at screenshot 2. I think there should be a change in the code. This thread is what I mean:

https://gamedev.stackexchange.com/questions/174107/unity-gyroscope-orientation-attitude-wrong

Edit 2: Your demo scene has the same problem

Oh, that is a different issue. You are talking about Gimbal Lock issue. That is correct. It exists in this tool. Because it uses Euler space to do math operations.

IvanMurzak avatar Jan 21 '24 22:01 IvanMurzak

What I want is the position of screenshot 1 (that's when it's lying on my table) when you hold the phone in your hands Edit: I have tried disabling and enabling gyro... and setting a new rotation for the cueb but he is always going to the rotation at screenshot 2. I think there should be a change in the code. This thread is what I mean: https://gamedev.stackexchange.com/questions/174107/unity-gyroscope-orientation-attitude-wrong Edit 2: Your demo scene has the same problem

Oh, that is a different issue. You are talking about Gimbal Lock issue. That is correct. It exists in this tool. Because it uses Euler space to do math operations.

Is there a way for you to add this into your tool or should I look for another tool. Because for what I need this tool would be perfect

craftercis avatar Jan 21 '24 22:01 craftercis

Is there a way for you to add this into your tool or should I look for another tool. Because for what I need this tool would be perfect

I would be happy if you could do that in a dedicated pull request. I am a bit busy right now. In another case, I will do that, but can't say when for now.

Edit: It should be a group of Gyro...3D components. That means don't need to modify Gyro...2D components, they are made for 2D games. Need to create new Gyro components instead.

IvanMurzak avatar Jan 22 '24 02:01 IvanMurzak

Is there a way for you to add this into your tool or should I look for another tool. Because for what I need this tool would be perfect

I would be happy if you could do that in a dedicated pull request. I am a bit busy right now. In another case, I will do that, but can't say when for now.

Edit: It should be a group of Gyro...3D components. That means don't need to modify Gyro...2D components, they are made for 2D games. Need to create new Gyro components instead.

I can try. Can you give me a direction where I should start?

Edit: I'm a bit neww to forking and editing open-source projects. I forked this project and cloned it to my laptop. But when I load it into Unity the package version is 1.2.6. That way I get 'Sirenix' errors that are solved in a higher version I saw.

Edit 2: Fixed this issue. I had to remove the Scripting Define Symbols' from the player settings :D

craftercis avatar Jan 22 '24 06:01 craftercis

Hey Ivan,

Sadly I couldn't fix the problem by myself. If you find the time, can you have a look at it?

craftercis avatar Feb 26 '24 09:02 craftercis