- Home /
Interpolating Positions, Networking
I was just using the Network View with the transform as observed. But it´s laggy so I tried to use RPC and interpolate each position.
//interpolation
var myMove : Vector3 = Vector3.zero;
var lastPos : Vector3 = Vector3.zero;
var cachePos : Vector3 = Vector3.zero;
var minMove : float = 0.01;
var curMoveValue : float = 0;
function Update(){
if(networkView.isMine)
{
//Sends position if I have move
if(curMoveValue > minMove)
{
networkView.RPC("SetPosition", RPCMode.OthersBuffered, transform.position);
cachePos = transform.position;
}
myMove = transform.position - cachePos;
curMoveValue = myMove.magnitude;
}
else
{
//We have move!
if(transform.position != lastPos)
{
myMove = lastPos - transform.position;
if(myMove.magnitude > 1)
{
var controller : CharacterController = GetComponent(CharacterController);
myMove = myMove.normalized;
controller.Move(myMove*moveSpeed*Time.deltaTime);
}
else
{
transform.position = lastPos;
}
}
It works fine, I ask you if there is a better way to do it. Anyway, the enmies are running the same code for syncing their positions but the problemen is when I istantiate new enemies in the scene. The positions of the new enemies between server and client do not match!
Im using this to create the new enemies:
function Update ()
{
if(Network.isServer)
{
if(myReady)
{
Crear();
}
}
}
function Crear()
{
myReady=false;
yield WaitForSeconds(delayTime);
var myenemy : Transform = Network.Instantiate(enemyTrans, transform.position, Quaternion.identity, 0) as Transform;
myReady=true;
}
But it doesnt work. Im also reciving this error: Could't invoke RPC function 'SetPosition' because the networkView 'AllocatedID: 3' doesn't exist
Help pls!
Your answer

Follow this Question
Related Questions
How to call a function from another script? 1 Answer
Unity crash when i use MasterServer.RegisterHost script 1 Answer
Help in Multiplayer 2 Answers
Spawning enemies in multiplayer 2 Answers
Please help with this code!! 1 Answer