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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Movements on serverside only? Passing variable to server

Discussion in 'Multiplayer' started by Kotiz, Sep 10, 2016.

  1. Kotiz

    Kotiz

    Joined:
    Feb 14, 2016
    Posts:
    1
    Hello, after learning unity for a while I'm now starting to check out multiplayer and read the multiplayer docs. I was wondering, what would be the safest and fastest way to do online movement?
    From what I understand, if I am to do MovePosition clientside and then have NetworkTransform copy it for everyone, players could exploit how they move since it's calculated on their end before being sent to the server.

    I'm thinking I pass the player inputs to the server and then on the server mathf.clamp to min -1 max 1.
    Do I pass the variable to the server using a [Command] called every x amount of a second? [SyncVar] seems to be only server-to-client.

    Am I missing something and there's a better way to go about what I'm trying to do?
     
  2. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    Syncvar is server-to-client, but you can still use a command to push an updated value and then the server sends that value to all clients.

    The way I do it is use a command that updates a position variable, position is a vector3 syncvar with a hook that calls a client function to update the destination of the navmesh. (So no networktransform)

    This way movement is always smooth even if there's latency cause it just takes the current position and moves the object to it's new position when it's received, but it depends what kind of game you're making and how accurate the positioning needs to be.

    I don't think you can do server side movement only, cause you still need to tell the server where you want to go :p
     
  3. Klounas

    Klounas

    Joined:
    Oct 10, 2013
    Posts:
    7
    Technically yes? I don't have an exact answer for you because from what I've gathered, depending on what type of game you're making, you don't want server side movement if you want good client-side control over it. You can always have a server side cheating check or get one of the many anti-cheat assets.

    In my case, trying to make just about everything server side just showed me that even if in theory it's the best for security, in the end you're just sacrificing game play efficiency for fake security. Some one will always find a way to cheat. Don't get me wrong though, you should still try to make things as server-sided as possible. But don't push it too far.
     
    Last edited: Sep 12, 2016
    Kotiz likes this.