Hi there!In my multiplayer game I want to synchronize a Character's rotation(with state synchronization), but only one axis. I would like the receiver just to receive the rotation of the one specific axis (looking left/ right), whereas the sender can also look up/down. The problem is, that I don't really know how to do so.^^ As said, I've only managed to sync the whole rotation... I'm also very confused with all the different types of rotation (Quaternion, eulerAngles, vector3(?)). .O Here is the code I got to synchronize (in C#):
/* I was wondering if any of you guys could help me out =). Any help would be appreciated. Thanks in advance */
(comments are locked)
|
|
Simply get the transform.eulerAngles.y (or x or z whatever you want) and put it in a float variable and then serialize it. when sending there is no problem. when receiving you should change the y rotation of the object to what you want and keep x and z with their previews values. the code would be something like this (the pother parts can be your own code).
using quaternions is not easy so don't use them if you really don't know them the Quaternion.Euler method takes the rotation as x,y,z in eulerAngles (360 degree angles that we know well) and then returns a quaternion value that is the same rotation and you can set transform.rotation to it. i did not tested but transform.eulerAngles might be writable too. Thanks for your answer! I tried your solution, but instead of rotating the character was just moving in some kind of circle (moving, not rotating =O). i also tried to directly change the transform.eulerAngles but it doesn't seem to be writable. .O The console also told me i had to instatiate and assign the rot variable in the else brackets. so it looks like this float rot = 0; stream.Serialize(ref rot); yRot = rot;
Apr 30 '11 at 08:42 PM
OpsicInstantPesic
(comments are locked)
|
