Search Unity

Rigidbody custom TCP/UDP client-server collaboration

Discussion in 'Physics' started by TheProxor, Jan 8, 2019.

  1. TheProxor

    TheProxor

    Joined:
    Apr 14, 2013
    Posts:
    1
    Hi there. I write my own framework for TCP/UDP Client-Server app (by Net.Sockets).
    Server - it's my Console Net Core app for Linux (I rent server with Ubuntu and install dotnet - Screen 1)
    Client - it's my game on Unity (Screen 2).

    I have a few cubes in Unity. Current client cube has rigedbody for motion. Other cube postion lerped by response from Server. For current client cube motion I use:

    Code (CSharp):
    1. rigidbody.velocity = new Vector3(Input.GetAxis("Horizontal"), -gravity, Input.GetAxis("Vertical")) * speed * Time.deltaTime;
    2.  
    After I send current position via UDP to Server, and Server send this position for other clients.

    What i want: if I has movement in current client and touch other cubes - they rigidbody receive velocity from me and move away from me.

    I know that I can detect touch rigidbody of first cube and collider of second, and send TCP command "AddForce" and make "Rigidbody.AddForce(recieved vector)", but there may be an easier way.

    For example, I remember was a Network Rigidbody... But this work only in Unity environment.



     
  2. Kennai

    Kennai

    Joined:
    Nov 1, 2018
    Posts:
    3
    Hello, TheProxor
    If I understand you well, your both clients emulate physics collisions?
    and server only transfer data from one client to all others? And you want to "sync" physics on clients? its very bad idea

    Instead of that, you may need one master client and few slave clients.
    Master client will emulate physics while slave clients will work only with objects without any colliders/rigidbody, just simple mesh or primitives.
    Master client will send positions of all objects to server (and server will transmit it to all clients) and slave clients will send only own player position or player keyboard & mouse state to server and server will transmit it to all clients (lets say, send state 20 times per second).
    Your master client will receive players state and move each player according that info.