Socket.IO & JSONOBJECT problem with floats

Hi, a year ago, working with the following multiplayer project using socketio and nodejs [https://github.com/AlexanderDykov/Unity-NodeJS-Game], everything worked perfectly. But now I find that the position between client-server-client does not work well.

The code is that:

  1. Send position to the server when player is moving:

  1. Recive position by Server and send to anothers gamers:

3.) recive data of another players moving:


Problem:
(server)

(client)

I cant convert this to vector 3. (parsing x string to float get error). And thats positions are wrong ( real position is x: 1,57 and y:4,23).

SOcketIO is deprecated and now unity use another system for make multiplayers games¿?¿?¿?¿?

Please try the proyect that i link in the head of post for know about i´m talking. TY

4177303--369364--Network.cs - Client - Visual Studio Code.jpg

…with unity 2017.3 work fine … using unity 2018 no…

hi, I took a look at your code and I think the best option is converting your data into a string then emit it to the server, I mean you can pass the data in string type instead of float because on the other hand when you are getting the data it is a string anyway

Hope my answer be helpful :slight_smile:

I resolve player.position.x = Mathf.Round(transform.position.x * 1000.0f)
on recive /1000

Same problem here. I don’t want to convert to string or multiply by 1000, this is no solution for me because i don’t want to change the JSON object on server side.

Hey, same or similar problem here. I also try it to multiply or divide it by 1000. During my debugging I have seen, that a big number will displayed as a exponential number and this can not be resolved by JsonUtility.FromJson(data) ? I enable Debugging for SocketIO:
[SocketIO] Raw message: 42[“userid”,{“name”:“”,“password”:“”,“user_id”:1,“email”:“”,“session_id”:“42fd7c09-adeb-948e-d267-f236de35b5d4”,“msgTime”:1579129255999}]

and after socketIOEvent.data.ToString(); i get:
NM: rec: userid: {“name”:“”,“password”:“”,“user_id”:1,“email”:“”,“session_id”:“42fd7c09-adeb-948e-d267-f236de35b5d4”,“msgTime”:1,579129E+12}

So data is transmitted in right way but loosing precision during internal execution in SocketIOComponent… On some other test floating point is ignored and just interpreted as integer like 1.00005 is after getting it in my class something like 100005

Im having this same issue now, were you ever able to resolve this?