Skip to content

Instantly share code, notes, and snippets.

@JosephShering
Created January 9, 2016 00:34
Show Gist options
  • Save JosephShering/eedc95ed3ec4ccc447ec to your computer and use it in GitHub Desktop.
Save JosephShering/eedc95ed3ec4ccc447ec to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class PlayerPositionSync : NetworkBehaviour {
[SyncVar]
private Vector3 syncPosition;
public Transform transform;
public float lerpRate = 15;
void FixedUpdate () {
TransmitPosition ();
LerpPosition ();
}
void LerpPosition() {
if(!isLocalPlayer) {
transform.position = Vector3.Lerp (transform.position, syncPosition, Time.deltaTime * lerpRate);
}
}
[Command]
void CmdProvidePositionToServer(Vector3 position) {
syncPosition = position;
}
[ClientCallback]
void TransmitPosition() {
CmdProvidePositionToServer (transform.position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment