To make the ‘Pointer’ rotate around the ‘Player’ relative to the ‘Camera’ Y rotation, using the Right JoyStick (Axis 4 & 5) of an Xbox Controller.
Example:
I want to be able to run left and shoot right, holding right on the JoyStick no matter where the camera is.
*Problem:
I’ve never used eularAngles or Quaternions before, Plus every time I manage to rotate it forward doesn’t stay forward when I rotate the ‘Camera’ Angle.
Objects:
Cylinder GameObject ‘Player’
Empty GameObject with texture attached ‘Pointer’
MainCamera
Here is a bit of untested code. It assumes that you’ve constructed your model so that the front is facing positive ‘z’ when the rotation is (0,0,0). ‘Vert_Axis’ and ‘Horz_Axis’ are whatever the names you are using for the vertical and horizontal component of the right joystick. And the vertical axis does come first in the Atan2:
var v1 = Camera.main.transform.forward;
v.y = 0.0;
var q1 = Quaternion.LookRotation(v);
var angle = Mathf.Atan2(Input.GetAxis("Vert_Axis"), Input.GetAxis("Horz_Axis") * Mathf.Rad2Deg;
var q2 = Quaternion.AngleAxis(angle + 90.0, Vector3.up);
transform.rotation = q2 * q1;