I am making a Unity Multiplayer game, and I wanted to compress the Y rotation axis from sending the whole Quaternion to just sending one byte.
- My first compression attempt:
- Instead of sending Quaternion, I have just sent a Y-axis float value
- Result: 16 bytes -> 4 bytes (12 bytes saved overall)
- Second compression attempt:
- I have cached lastSentAxis variable (float) which contains the last Y-axis value that has been sent to the server
- When a player changes their rotation (looks right/left), then a new Y-axis is compared to the cached one, and a delta value is prepared (delta is guaranteed to be less than 255).
- Then, I create a new sbyte - which contains rotation way (-1, if turned left, 1, if turned right)
- Result: 4 bytes -> 2 bytes (2 bytes saved, 14 overall)
- Third compression attempt (failed)
- Define a byte flag instead of creating a separated byte mentioned before (1 - left, 2 - right)
- Get a delta rotation value (as mentioned previously), but add it to the byte flag
- PROBLEM: I have looped through 0 to 255 to find which numbers will collide with the byte flag.
- POTENTIAL SOLUTION: Check if flag + delta is in the colliding number list. If yes, don't send a rotation request.
- Every X requests, send a correction float value
- Potential result: 2 bytes -> 1 byte (1 byte saved, 15 overall)
My question is, is it possible to make a third compression attempt in a more... proper way or my potential solution is only possible thing I can achieve?