I’m trying to learn 3d programming and I have a hard time this problem though sounds like it should be extremely easy but nothing I tried seem to work.
I currently have a spaceship, I want to build a steering thruster which applies force to the spaceship depending on the current rotation magnitude.
I assume I’m using the math functions incorrectly but I can’t understand what I should use instead. Most of my issues stem from that what I do works as long as I don’t rotate the ridgidbody, I tried using local rotation instead but that didn’t work either.
The Unity “Euler Angles” concept should not be used anywhere near flight systems. They’re always applied in the order of Z first, X next, Y last, which is helpful for land-based vehicles in a Y-up world, but will completely mess your orientation up if you’re trying to work in terms of flight dynamics like yaw, pitch, and roll. For flight dynamics, you want to apply your composite angles in the order of Yaw first, Pitch next, Roll last, which in Unity’s Z-forward world is Y X Z.
This converts a given yaw, pitch, roll into a suitable Quaternion for your aircraft.
Unfortunately, even with a fair bit of experimentation and searching on my part, I have not yet found a good solution that implements the reverse: given a normalized Quaternion in Unity’s left-handed universe, return the angles for yaw, pitch, roll.
Were you and to solve the reverse yet? I’ve been experimenting and searching as well for the last two weeks and it seems impossible to get y,p,r local to the ships local orientation.
I’m trying to export orientation telemetry for a motion rig .
its a 6dof game , i would like it so that regardless of which way your nose is facing . eg if rolled right , turning left and right would still be yaw(around local y-axis) and not pitch(around global x-axis).
i tried to realign the objects rotation with Vector3.forward so i can measure
private static float MeasureRoll(Transform transform)
{
var rotation = transform.rotation;
var qFwd = transform.forward.ToQuaternion();
var unfwd = Quaternion.Inverse(qFwd);
var fwdAlignedRot = (rotation * unfwd).Normalized();
return fwdAlignedRot.eulerAngles.z;
}