# Measuring Local Rotations

What I thought was going to be simple, is not turning out to be the case. Can anyone assist me with pulling a local rotation around a pivot point for a virtual joystick using a Vive controller?

I’ve used the following lines:

``````Roll = Mathf.RoundToInt(transform.localRotation.eulerAngles.x);
Pitch = Mathf.RoundToInt(transform.localRotation.eulerAngles.z);
``````

But the values I get are wacky (X and Z change when only rotated around 1 axis) and don’t represent the true rotations which should be somewhere between -30 and 30 degrees. Is there a simple way to pull this information from the rotating object? I’ve tried multiple other ways, but no matter what I do, I can’t seem to pull a simple X and Z rotation around the local pivot point. I’ve attached the script to the virtual joystick…

Well do you know the default rotation of the joystick? Try printing all three values and find it’s 0.

I’ve tried zeroing out the X and Z axis so my center point is 0,0,0, but I still get funky translations on the value of Pitch and Roll. For example, my true starting rotation is 270, 0, 90. When I move the joystick -30 or 30 degrees in the X direction, the value of Roll = 300 (instead of 240 and 300), but my Z value changes to 60 and 270 (instead of staying at 90) and the Y value changes to 90. A similar thing happens when I rotate 30 degrees around the Z axis, but the numbers are different. It seems very strange since the joystick rotates perfectly around it’s pivot point and works with the Vive controller. Could this have something to do with the center point and pivot point being at different location? Or is there different code I need to use in order to pull a value equal to the true rotation around that particular axis?

Do contolers even use euler rotations? I would expect quaternions for axis lock prevention.
Also I have no dea what you mean by

Degrees aren’t distance measurement. Did you mean rotate 30/-30 degrees over X axis?
But from the values you provided I would say you are actually rotating over Z axis (YAW - (left/right)) and not X axis (PITCH - (up/down)). No Idea why Y would change to 90, though.

I recommend drawing something in the scene that would represent a controller, binding it to joystick’s transform properties and observing changes. Maybe you’ll figure it out that way. Maybe the axis are not in the order you would expect them to be.

Thanks for the suggestions. I worked on this for several hours yesterday and finally got everything working (sort of). I needed to move the child objects out of the parent to reset the rotations to 0,0,0. Then adjusted the rotation of the parent as needed. Now the angles on the configurable joint are providing the correct rotations. I also added about 6 lines of code to use Quaternion rotations around the Configurable joint instead of using eulerAngles - I found that code on the forums which basically simulates HingeJoint.angle around a configurable joint. But of course, new problems now arise with the physics aspects. When I move the throttle lever forward and the ship begins the accelerate, the throttle stick and joystick begin to move (opposite the direction of acceleration) due to the external forces causing unwanted rotations. Even worse, when the acceleration (or velocity) gets too high, the joystick and throttle lever literally fly off the hinge! Now I need to deal with that. Very frustrating, but still a very fun learning experience.

Not sure if this has something to do with how I am applying the throttle / force/ velocity to the ship, or if there is a way to have items inside the ship (objects as a child) to ignore the external forces.