Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve "Gimbal Lock" problem by using Quaternion for rotation #3

Open
craftercis opened this issue Jan 21, 2024 · 9 comments
Open
Labels
enhancement New feature or request question Further information is requested

Comments

@craftercis
Copy link

craftercis commented Jan 21, 2024

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

@IvanMurzak
Copy link
Owner

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 IvanMurzak added the question Further information is requested label Jan 21, 2024
@craftercis
Copy link
Author

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
Copy link
Author

craftercis commented Jan 21, 2024

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

@IvanMurzak
Copy link
Owner

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
Copy link
Owner

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.

@craftercis
Copy link
Author

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

@IvanMurzak
Copy link
Owner

IvanMurzak commented Jan 22, 2024

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 IvanMurzak changed the title Start rotation offset Resolve "Gimbal Lock" problem by using Quaternion for rotation Jan 22, 2024
@IvanMurzak IvanMurzak added the enhancement New feature or request label Jan 22, 2024
@craftercis
Copy link
Author

craftercis commented Jan 22, 2024

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
Copy link
Author

Hey Ivan,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants