- Home /
LAN Networking optimization. Dead reckoning: targeting problems in JavaScript
Hi everyone,
I'm trying to use Dead Reckoning: Targeting (http://www.gamedev.net/reference/articles/article1370.asp) to improve the networking in a game. The character follows a "dummy" target received by network. The server computer seems to work almost fine, but the client gets a really laggy movement of the server character (I only test two player game). I use a RPC call from the owner of the character to the others (RPCMode.Other), with the transform.position to make a target. The direction is calculated doing: transform.position - lastPositionReceived and the attribute normalized in the Vector3 class. The target speed is predicted with the user input*speed. Here is my code:
function Update () {
if(remote){
//Moving target
//_targetPosition = _targetPosition + (_lastDirection* _targetSpeed);
_targetPosition = Vector3(_targetPosition.x,0,_targetPosition.z) + Vector3(_lastDirection.x * _targetSpeed,2.38f,_lastDirection.z*_targetSpeed);
//Converge to Target. Target is moving
transform.position = (transform.position*99 + _targetPosition)/100;
//transform.position = Vector3.Lerp(transform.position, _targetPosition, Time.deltaTime);
if(!animation.IsPlaying("Front_Walk") && _targetSpeed != 0) animation.CrossFade("Front_Walk");
//Not very smooth rotation but it's ok
transform.rotation = Quaternion.Slerp(transform.rotation,_lastRotation, Time.deltaTime);
}
}
I tried to use the Network view component observing the transform but it's really laggy. Any tip please?
Thank you very much! And sorry about my bad English!