Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Socket.IO & JSONOBJECT problem with floats

Discussion in 'Editor & General Support' started by gonzalodelpalacio, Feb 3, 2019.

  1. gonzalodelpalacio

    gonzalodelpalacio

    Joined:
    Mar 10, 2018
    Posts:
    5
    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:



    2. 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
     

    Attached Files:

    Last edited: Feb 3, 2019
  2. gonzalodelpalacio

    gonzalodelpalacio

    Joined:
    Mar 10, 2018
    Posts:
    5
    ...with unity 2017.3 work fine ...... using unity 2018 no..
     
  3. mehdi76r

    mehdi76r

    Joined:
    Jul 29, 2017
    Posts:
    1
    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 :)
     
  4. SergioCamoleze

    SergioCamoleze

    Joined:
    Jul 26, 2016
    Posts:
    1
    I resolve player.position.x = Mathf.Round(transform.position.x * 1000.0f)
    on recive /1000
     
  5. cert

    cert

    Joined:
    Feb 10, 2013
    Posts:
    24
    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.
     
  6. LONyTOOn

    LONyTOOn

    Joined:
    Sep 24, 2018
    Posts:
    1
    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<T>(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
     
  7. vulaman

    vulaman

    Joined:
    May 14, 2014
    Posts:
    1
    Im having this same issue now, were you ever able to resolve this?