Hello,
This is a very difficult question to explain so if it is not clear please tell me.
I have a flying game were I rotate an object in z axis to roll it and x for pitch (up/down). My code is such:
transform.localEulerAngles = new Vector3(ElevatorAngle, 0, -RollAngle);
The angles are calculated on the fly by the positions of fingers on the screen and thats why I dont use Rotate because I want to set it to a particular rotation.
The problem is when the aircraft has rolled to one side you would want it to use up pitch so the plane can turn, flight sim people will know instantly what I mean.
The problem is the way I feed in x and z rotation angles. This seams to prevent rotating in x, and then y based on the previous rotation (x).
You can test this in Unity by rotating something in x with the widget and then in z after the previous rotation. You will see in the object transform some interesting rotations come up.
I cannot seem to be able to recreate this in-game. This is a commercial project and I really need the help!
Thank you for your time!
EDIT: Basically how can I combine the rotations?
EDIT: Has been fixed thanks to Spreos, here’s the final code:
//Make Rotations
Quaternion Pitch = Quaternion.Euler(ElevatorAngle, 0, 0);
Quaternion Roll = Quaternion.Euler(0, 0, -Angle);
//Rotate Character
transform.localRotation = Roll;
transform.localRotation *= Pitch;