- Home /
Can't Accurately Read Rotations
I have been working on a project recently in which I am taking rotation inputs from an Arduino and displaying it through Unity. I have the data sent as Quaternions through the Serial Port where Unity is able to use the data. Anyways, my goal is for the rotation data to make an animation play in Unity. I have my animations set up so that I can send a float 0 - 1 that correlates with a certain frame of the animation, that way I can have the rotation relate to the position of the animation. The problem that I am having however, is accurately reading the rotation. I cant use the raw Quaternion data and converting it into Euler angles produces erratic behavior such as going from a low to high to low value or skipping ahead 90 degrees randomly.
BTW: I am not displaying the rotations with Physics because I want control over certain axis while the others stay relative to the data from the Arduino. Also it isn't as smooth.
What kind of device is generating the rotation info for the Arduino? A full XYZ device like a gyro or gravity sensor, or a device that gets X and Y rotations separately like a joystick?
Why can't you use raw Quaternion data? If you already have the quaternion representation in the Arduino then sending over w,x,y,z, values seems the easiest.
If you do want to use the Euler angles, keep in $$anonymous$$d that different systems use different Euler conventions, and its very likely that whatever convention your arduino uses does not match what Unity uses. This is why sending over pure quaternion data is best if possible, but a workaround for this is to look up the mathematical conversions from whatever euler convention the arduino uses to a quaternion.
I am already sending the data to Unity as quaternions however, I'm not still super familiar with quaternions and don't understand the conversions. I just need to convert those into an animation position rather than just setting the rotation of the object to that quaternion rotation.