O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preparing for server authoritative movement

Before we get started, we'll need to restructure our scripts. We're going to change the Update function so that it isn't called automatically, and instead will be called by our networking scripts. We need to do this so that we have direct control over the exact order in which the simulation is stepped, otherwise we can easily end up with desyncs and rubber banding.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
  public float MoveSpeed = 5f;

  [System.NonSerialized]
  public float horizAxis = 0f;
  [System.NonSerialized]
  public float vertAxis = 0f;

  void Update()
  {
    if( networkView.isMine )
    {
      horizAxis = Input.GetAxis( "Horizontal" );
 vertAxis = Input.GetAxis( "Vertical" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required