Get heading of an entity

I simply want to convert an entity's orientation property (entity.orientation - quaternion) to heading (degrees). How do I do that?


If you’re just trying to set an entity’s orientation, you can use Transforms.headingPitchRollQuaternion to supply the heading/pitch/roll and get a quaternion you can set the entity’s orientation to. See:

If that doesn’t work for you, can you tell me a bit more about your use case and what you’re trying to do?

I'll try to explain it better. There is a better way to do this probably.

I have a time dynamic entity, which changes orientation over time. The orientation is a SampledProperty. What I need is to calculate the entity's heading at any time, and I thought it wouldn't be a good practice to also store the heading as a SampledProperty.

Instead what I'm trying to do is get the heading by calculating it from the orientation quaternion.

let orientation = entity.orientation.getValue(currentTime);
let heading = ?

I see what you mean now. Looks like you can just use the HeadingPitchRoll.fromQuaternion function, which you can then extract the heading from in radians and then convert to degrees.