Rotate a Joystick gameobject depending on axis values to represent the actual joystick press

Hey,

I’m currently stuck on a (probably simple) rotation task.


I have a Joystick gameobject in a VR game the player can grab. Once he does, the player’s hand snaps to the joystick in a holding animation. While the hand is attached i get x and y values between -1 and 1 to represent the current joystick position.

Now i want to rotate the joystick gameobject by about 25° in a positive or negative direction depending on the values i’m getting on both the x and y axis, the goal basically is to give the player a visual representation of where he is tilting the joystick.
So if you did it with a simple gamepad i want a visual representation ingame of the real joystick position.


I’m pretty new to rotations and quaternions and have been playing around with Quaternion.Lerp and Quaternion.EulerAngles, but haven’t been able to achieve the desired result.

Can anyone point me in the right direction? (pun intended :p)

Thanks in advance!

Kawa

Managed to find a fix myself!


// creating a vector3 with this frame's values for x and y rotation
leverEulerAngles = new Vector3(joystickXAxisRotationValue, joystickYAxisRotationValue, 0); 

 // passing from Vector3 to Quaternion type
leverRotation.eulerAngles = leverEulerAngles;

// setting the actual rotation
leverRotationPivotPoint.transform.localRotation = leverRotation;

The trick was to have a seperate Vector3 to store the needed euler angles and pass that to a placeholder Quaternion before applying it to the actual Quaternion i wanted to rotate.