No that is not working for me, because i read the RAW data from a Arduino MPU 6050 Gyroscope.
First i have limit the rotation with slerp, so the physic engine do not struggle.
I have qy qx qz and qw.
My idea was to create a newVector and set the qz and qw to zero.
But when i do this the rotation runs in trouble:
i have also tried to attach a rigid body and fix the z rotation, but the values are protected, so i need to do this in code.
Just explaining this so I am sure I understand what you are doing. You have some GameObject in your Unity Scene. You have an realworld gyroscope that is moving around in a all 3 axis. You read that data and copy it so your Unity Object rotates the same way. Now you would like to limit this so it only rotates forward and pans around. No spinning around the z- Axis?
float initialZ;
void Awake()
{
initialZ = transform.eulerAngles.z;
}
void Update()
{
// All your code to get a rotations from the Arduiino
Quaternion rotation = // your code to get the rotation from the gyroscope
Vector3 eulerAngles = rotation.eulerAngles;
eulerAngles.z = initialZ;
rotation = Quaternion.Euler(eulerAngles);
}
Now you have just the x,y components of your rotations with the original z rotations from the program start.
Its because your copying the transforms local rotation into a a variable called rotation. then setting the z value on that rotation but never sticking it back into the transform.
I moved the removal of the Z axis rotation to the OnRotationChanged EvenHandler
Also i changed your _fromRotation to equal the current rotation, not the former _toRotation. This makes more sense because if we are in the middle of Slerping to the _toRotation and the user moves again before we get there. We don’t want to instantly jump to our former target then start Slerping again. We just want to start SLerping from where we are to the new target.
Edit: Had a bug in the code setting _toRotation. Fixed now if you copied it before this edit need to change to the new version.
hmm i try this out, but i see no jumping or jitter.
But thanks.
When i release this stuff in 2-3 weeks, i do this for free. So if you have a “Wackel board” and Arduino with MPU you can play it.
currently my feet are burning by testing