I am creating an MMORPG and I’ve got a mysql database which is all designed to copy the design on Unity… at least almost entirely…
I have a Transform table with foreign keys to entries on a Vector3 table which stores X, Y, and Z float values. This much all works. I have stored procedures for updating the location and rotation of the player, as well as for pulling the values.
the issue I’m having is in which values to store IN the database for Rotation… I have spent the last 5+ hours looking online for help… I’m aware that Euler can be represented in many ways and mean the same thing and understand a gimbal lock so please don’t clutter a response with that stuff. Very simply put, I’ve tried storing the x,y,z from Transform.localRotation and from Transform.localEulerAngles (it needs to be local, as it is the camera on the player, child’ed to a child of the player (perhaps this is part of the issue? - using global I’ve also tried and it also fails.)
here’s the code for storing and for getting the rotation (I have a custom Command Method to clean up the number of code lines for my simpler database procedure calls.)
private void Update()
{
if (Input.GetKeyDown(KeyCode.U))
{
print("Updating Rotation on Server to : " + character.transform.GetChild(3).GetChild(0).eulerAngles + "
");
PlayerData.Command(“UpdateEulerRotation”, new MySqlParameter {
new MySqlParameter(“inUsername”, PlayerData.GetUsername()),
new MySqlParameter(“inPassword”, PlayerData.GetPassword()),
new MySqlParameter(“inCharacterName”, PhotonNetwork.player.NickName),
new MySqlParameter(“inRotX”, character.transform.GetChild(3).GetChild(0).localEulerAngles.x),
new MySqlParameter(“inRotY”, character.transform.GetChild(3).GetChild(0).localEulerAngles.y),
new MySqlParameter(“inRotZ”, character.transform.GetChild(3).GetChild(0).localEulerAngles.z)
});
}
if (Input.GetKeyDown(KeyCode.S))
{
character.GetComponent<FirstPersonController>().enabled = false;
PlayerData.Command("GetCharacterEulerRotation", new MySqlParameter[]
{
new MySqlParameter("inUsername", PlayerData.GetUsername()),
new MySqlParameter("inPassword", PlayerData.GetPassword()),
new MySqlParameter("inCharacterName", PhotonNetwork.player.NickName)
}, true);
character.transform.GetChild(3).GetChild(0).localEulerAngles. = new Vector3(
(float)PlayerData.ResponseTable.Rows[0]["Vector3_X"],
(float)PlayerData.ResponseTable.Rows[0]["Vector3_Y"],
(float)PlayerData.ResponseTable.Rows[0]["Vector3_Z"]
);
character.GetComponent<FirstPersonController>().enabled = true;
}
}
To shorten any concerns, as I stated previously, the “talking to the database” part is working fine. I get back the X, Y, and Z float values individually, but whenever I apply them, the rotation is WAY off.
I will resort to creating an entirely new table to represent quaternions if I must, but I would really prefer to keep it condensed into one vector3 table.