Hi, I need help… I am using NodeJS as a server for the network gaming
when I am trying to send the position of the player using JSONOBJECT I am getting Null on the server
public SocketIOComponent socket;
public void OnMove(Vector3 position)
{
// Send position to node
Debug.Log("Sending Position to Node: " + VectorToJson(position));
socket.Emit("move", new JSONObject(VectorToJson(position)));
}
string VectorToJson(Vector3 vector)
{
return string.Format(@"((""x"":""{0}"", ""y"":""{1}""))", vector.x, vector.z);
}
}
Server Code:
var io = require(‘socket.io’)(process.env.port || 3000);
console.log(“Server started”);
var playerCount = 0;
io.on(‘connection’, function(socket){
console.log(“Unity clinet connected…, broadcasting spawn”);
socket.broadcast.emit('spawn');
playerCount++;
for(i = 0; i < playerCount; i++){
socket.emit('spawn');
console.log("Sending spawned player to new clients");
}
socket.on('move', function(data){
console.log('client moved', JSON.stringify(data));
socket.broadcast.emit('move', data);
});
socket.on('disconnect', function(){
console.log("Client disconnected");
playerCount--;
});
})