Posting this here because I spent several days trying to figure out why I couldn't rotate my entities the way I wanted to in Unity.
For a little bit of background, I'm creating a flight dynamics model using Unity's Entities package. Part of this project involves providing keyboard input to a system in order to manipulate the motion of an aircraft--a very basic simulator.
I encountered an issue when I tried rotating my aircraft entity using the Rotation.Euler() method. In fact, just about every approach I saw on every forum I visited could not provide the answer I was looking for. My keyboard input logic manipulated the bank angle (roll), alpha (pitch), and yaw, and I was trying to set an absolute angle for my entity based on those values. It seemed that I was unable to set the rotation values the way I would in the inspector panel, since rotating the entity one direction would make rotating it along another axis unpredictable.
Such is the nature of quaternions.
Thus, I found a solution to my issue, involving a simple helper function that converts a float3 array of rotation values (one for each axis) to a quaternion. I'll be posting the code and explanation in the answer below.
EDIT: In the previous iteration of my code, this is what I had tried in order to update my entity's rotation:
Vector3 temp = transform.rotation.eulerAngles;
temp.x = -90.0f + state.bank;
temp.y = 0.0f;
temp.z = state.alpha;
Entities.ForEach((ref Translation translation, ref Rotation rotation, ref AircraftData aircraftData) => {
translation.Value = position;
rotation.Value = Quaternion.Euler(temp);
}).Schedule();
All other code within the answer below was the same (minus the new quaternion calculations).
Quaternion.Euler
for a one-way conversion to quaternion from that persistent source of truth? \$\endgroup\$