I am using 2021.3 and XR Integration Toolkit. I am testing with an Oculus 2, or Quest 2, whatever they call it now, through Steam VR/Oculus Link. I’m having an issue where, when I rotate the player using thumbsick, it creates some alignment issues.
About my project. The player has a jetpack. I am using continuousMovement on the left controller to move the player when they are on the ground. The player also has a rigidbody components, and I’m using physics and the right controller to allow them to thrust up, and move when they are in the air (right grip is thrust up, right control stick thrust them directionally forward, backward, left or right). This all works really well, and I based it on this tutorial:
So, my setup is:
I have created an XR Origin. On this, I have my Locomotion and Continuous Movement Provider. I also have a capsule collider and rigidbody. And, of course, I have my jetpack script.
I determine thrust direction basesd on the x,y input of the right thumbstick:
thrustDirection = Camera.main.transform.forward * secondaryThrustInput.y + Camera.main.transform.right * secondaryThrustInput.x;
And I apply that thrust with an AddRelativeForce().
This works great. If I turn my head and thrust forward, I thrust where I’m looking. If I turn myself physically while I’m flying, I can change the way I’m going, and thrust directions all work well.
The problem arises when I’ve tried adding a function to rotate the player using the jetpack and right controller. The idea is, I want the player to not have to turn their feet to rotate. It makes sense if they use their feet to rotate themselves when they are on the ground, but when they are flying, I want them to be able to use the jetpack thrust to rotate themselves.
I’ve been able to rotate using my own script, or using the Continuous Turn Provider. But, whenever I rotate, my thrust direction no longer works as expected (even though Continuous Movement does). So, after rotating, if I thrust forward, I’m not going forward but some other direction. And, if I rotate again, it will go in another different direction. I’ve tried various solutions to this… I’ve tried Rotate, RotateAround, I’ve tried creating a parent object for XR Origin and rotating that. They all lead to the same result.
I’m not fully grasping some aspect of either my directional thrusts, or the rotate systems. Can anyone provide some insight on a solution to this? I would like to keep the rigidbody and physics forces if at all possible (for thrusting up and thrusting directionally, not for rotation). I do have rotations frozen on my rigidbody but have also experimented with unlocking Y rotation, to no avail.
I’ve tried rotation calculations as such:
_xrOrigin.transform.parent.RotateAround(new Vector3(Camera.main.transform.position.x, 0, Camera.main.transform.position.z), Vector3.up, secondaryThrustInput.x * 50 * Time.deltaTime);
Quaternion rotationDelta = Quaternion.Euler(0, secondaryThrustInput.x * 50 * Time.deltaTime, 0);
_xrOrigin.transform.rotation *= rotationDelta;
Video demonstration of issue (shows head turn and thrust direction working, but then 90 degree rotate and thrust goes in wrong direction): https://cdn.discordapp.com/attachments/1099009674017243187/1099016251226980482/Unity_2023-04-21_12-57-20.mp4
TY!