# how does unity store player orientation for 3d flight sims?

This topic is 1992 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

how does unity store player orientation for 3d flight sims?

i recently played an alpha of a space fighter sim done with unity and was very impressed with the accuracy of the local rotations (then again, it was not running at extremely high screen resolution).

how does unity store the player's current orientation? as a float x,y,z rotation component? and computes the world transform from those as needed?

##### Share on other sites

The rotation of any object in Unity is stored as a quaternion in the transform component.

##### Share on other sites

The rotation of any object in Unity is stored as a quaternion in the transform component.

and they handle incremental rotation quat float error by renormalizing the quat?

if so, how often? after each rotation?

doe the engine do this automatically?

or is that up to the implementer?

in the past i've used Eulers and recalculated the world matrix as needed, local i,j,k vectors and gram schmitt, and matrices and gram-schmitt. just different was to skin the same cat. but apparently quats won't "go south" on you as quickly due to float error, but still require occasional re-normalizing.

##### Share on other sites

The rotation of any object in Unity is stored as a quaternion in the transform component.

and they handle incremental rotation quat float error by renormalizing the quat?

if so, how often? after each rotation?

doe the engine do this automatically?

or is that up to the implementer?

in the past i've used Eulers and recalculated the world matrix as needed, local i,j,k vectors and gram schmitt, and matrices and gram-schmitt. just different was to skin the same cat. but apparently quats won't "go south" on you as quickly due to float error, but still require occasional re-normalizing.

The quaternion in unity should be(there is no normalize method) normalized automatically so you shouldn't have to worry about that.

Edited by SimonForsman

##### Share on other sites

The quaternion in unity should be(there is no normalize method) normalized automatically so you shouldn't have to worry about that.

i'm not a unity user, so that's not the concern. i was curious as to their implementation method, as it seems to work well.

so there's no user called normalize() function.....        they probably do it each frame after applying rotations.

##### Share on other sites

i'm not a unity user, so that's not the concern. i was curious as to their implementation method, as it seems to work well.

so there's no user called normalize() function.....        they probably do it each frame after applying rotations.

I haven't looked into unity either, but I assume this is the case.

##### Share on other sites

I calculate new normalized quaternion from old one, angular velocity(vec3) and delta time like this.

Quaternion newOrientation = normalize(orientation + (orientation * Quaternion(angularVelocity, 0.0f)) * deltaTime);

This is really fast and can even further optimized because we know that quaternion from angular velocity and 0 have zero w component but good compiler should do this on its own.

##### Share on other sites

I calculate new normalized quaternion from old one, angular velocity(vec3) and delta time like this.

3d degrees of local rotational freedom flight simulator application?

how pixel perfect are your rotations?

can you rotate to an arbitrary orientation, then do a 360 around any local axis, and end up looking at the exactly the same pixel as when you started the 360?  at 1600x900 resolution?  or do you get "drift" ?

the issue here is accuracy, not speed. floats are inherently too inaccurate to handle incremental rotations without fixups like re-ortho-normalizing.

and fixups only keep the error to a minimum, they do not eliminate it completely.

even a system that is pixel perfect doing a 360, will break down and start to drift by the by 5th or 6th 360 in a row using mats. same for quats, just takes longer.

this is very important in flight sims.  if you turn around, then turn back around, the bad guy who was in front of you should still be in front of you, not below, above, to the left, or to the right.

in the unity game i was playing, i could do 4 or 5 360's with no sign of drift. i didn't try any more than that.

again, it may be the somewhat low resolution they were running at (maybe 800x600?).

Edited by Norman Barrows

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634150
• Total Posts
3015827
×