The title is hopefully not too bad, however the issue I'm facing seems to be related to the "space" being used and thus seems important. So in short, I'm working on a game in which the user can rotate an object using the mouse. It works to a degree only, this is the current code (currently being called upon the update function):
float mouseX = 0, mouseY = 0;
var delta = Mouse.current.delta.ReadValue();
mouseX += delta.x;
mouseY += delta.y;
mouseX *= mouseSensitivity * Time.deltaTime;
mouseY *= mouseSensitivity * Time.deltaTime;
float XaxisRotation = (mouseX * rotationSpeedMultiplier) / grabbedObjectMass;
float YaxisRotation = ((mouseY*-1) * rotationSpeedMultiplier) / grabbedObjectMass;
grabbedObject.transform.Rotate(Vector3.down * XaxisRotation, Space.Self);
grabbedObject.transform.Rotate(Vector3.right * YaxisRotation, Space.Self);
It works in the sense that I can rotate the object. However it immediately feels bad once you turn it too much and thus it no longer behaves in a relatable way. I'm using Space.Self and that means that rotation uses the objects own X,Y,Z coordinates, Space.World would use the scenes X,Y,Z as far as I understand it. This is with Space.Self using my Photoshop skills just to illustrate the problem: object specific rotation
Now what I want instead is that it will always rotate "properly" according to the players perspective or the players X/Y/Z. So no matter what side I look on, it should just rotate the same as it uses the player as space - if that makes any sense. However, the only options seem to be Space.Self and Space.World.
I've seen games do it so it's definitely possible and probably not super complicated, but I just don't know how yet. I've tried this alternative code (copied and adapted) from the Unity Docs, however it behaves exactly the same as the code above using Space.Self:
float mouseX = 0, mouseY = 0;
var delta = Mouse.current.delta.ReadValue();
mouseX += delta.x;
mouseY += delta.y;
mouseX *= mouseSensitivity * Time.deltaTime;
mouseY *= mouseSensitivity * Time.deltaTime;
float XaxisRotation = (mouseX * rotationSpeedMultiplier) / grabbedObjectMass;
float YaxisRotation = (mouseY * rotationSpeedMultiplier) / grabbedObjectMass;
Vector3 EulerAngleVelocity = new Vector3(YaxisRotation, XaxisRotation, 0f);
Rigidbody rb = grabbedObject.GetComponent<Rigidbody>();
Quaternion deltaRotation = Quaternion.Euler(EulerAngleVelocity * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotation);
I honestly don't fully understand rotation, Quaternions etc. just yet. Any pointers would be appreciated!