Skip to content

Instantly share code, notes, and snippets.

@SixWays
Created November 5, 2017 18:07
Show Gist options
  • Save SixWays/de3f20c1a5558db77a037fced823f949 to your computer and use it in GitHub Desktop.
Save SixWays/de3f20c1a5558db77a037fced823f949 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkTransformLerp : NetworkBehaviour {
public Transform target;
Vector3 _lastPos, _nextPos;
Quaternion _lastRot, _nextRot;
float _lastSyncTime;
NetworkTransform _nt;
void Awake(){
_nt = GetComponent<NetworkTransform>();
}
void LateUpdate () {
if (isLocalPlayer) return;
if (_nt.lastSyncTime != _lastSyncTime){
_lastSyncTime = _nt.lastSyncTime;
_lastPos = _nextPos;
_lastRot = _nextRot;
_nextPos = transform.position;
_nextRot = transform.rotation;
}
float t = Mathf.InverseLerp(_lastSyncTime, _lastSyncTime + _nt.sendInterval, Time.time);
target.position = Vector3.Lerp(_lastPos, _nextPos, t);
target.rotation = Quaternion.Slerp(_lastRot, _nextRot, t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment