A proper way to load player orientation?

Greetings. I currently have a system that saves the current player worldOrientation in a external .sav file.
It’s all nice and dandy (converted matrix in to a list).

My question is. What would be the proper way to load it and set the player orientation to match this value?
I have studied and read https://sites.google.com/site/socialstorage/orientationmatrix-basics
and according to that, just setting the orientation might cause the mesh to deform.

Is there something I should take to account with this? I managed to crash my game once already while testing my game and I wonder if this might be the cause.

I believe if you set all of the cells of the matrix you shouldn’t get distortion. EDIT: since you’re parsing the matrix into list before saving, make sure you parse it back to matrix properly before assigning it to player orientation. Could be why you get errors.

Or if you want to play safe you could always store and set the orientation in euler.


#Saving
def getPlayerOrientation():
    return player.localOrientation.to_euler()

orientation = getPlayerOrientation()
Save("PlayerOrientation", orientation) #however you save it


#Loading
def setPlayerOrientation(xyz):
    player.localOrientation = xyz

orientation = ReadSave("PlayerOrientation") #again however you read the save
setPlayerOrientation(orientation)

EDIT: to_euler() is a matrix function so you can also call it for your saved orientation matrix just before assigning the player orientation if you want to change your save/load system as little as possible.

It is no problem to store/restore the 3x3 part of the matrix as long as you do not skip or modify a term. The 3x3 part includes orientation and scale.

You can include the translation (position) by storing/restoring the complete transformation matrix which is a 4x4. You get and set it with KX_GameObject.worldTransform (without -ation).

I suggest you see the matrix as a whole. Avoid to modify just parts of it. I guess that is what the article is warning you about. If you set and get all terms at once you should be fairly save.

Oh… makes sure you do not create a transposed matrix on restore ;).