interpolated position good in log but choppy in render

hi
i have a wierd problem with my network interpolation script. When i log the positon of the interpolated character (Debug.Log(transform.position)) the position numbers seems to be running smoothly:

transform.pos : (-1.9, 16.7, -180.0)
transform.pos : (-1.8, 16.7, -180.0)
transform.pos : (-1.7, 16.7, -180.0)
transform.pos : (-1.6, 16.7, -180.0)
transform.pos : (-1.5, 16.7, -180.0)
transform.pos : (-1.4, 16.7, -180.0)
transform.pos : (-1.3, 16.7, -180.0)
transform.pos : (-1.2, 16.7, -180.0)

but on the screen the characters motion is really choppy and it clearly jumps back and forth

Does anyone have any suggestions of what could be wrong. This is driving me crazy!

function Update()
{
if(!Network.isServer)
{
//transform.position+=Vector3( 1,0,0);
// This is the target playback time of the rigid body
var interpolationTime:Number = Network.time - m_InterpolationBackTime;

if(m_TimestampCount>1)
{
// Use interpolation if the target playback time is present in the buffer
if (m_BufferedState[0].timestamp > interpolationTime)
{
Debug.Log(“interpolate”);
// Go through buffer and find correct state to play back
for (var i=0;i<m_TimestampCount;i++)
{
if (m_BufferedState*.timestamp <= interpolationTime || i == m_TimestampCount-1)*

  • {*
  • // The state one slot newer (<100ms) than the best playback state*
  • var rhs:State = m_BufferedState[Mathf.Max(i-1, 0)];*
  • // The best playback state (closest to 100 ms old (default time))*
    var lhs:State = m_BufferedState*;
    //Debug.Log("timestamp[0]: "+ m_BufferedState[0].timestamp);
    //Debug.Log("timestamp "+m_BufferedState.timestamp);*

* //Debug.Log(i);*
* //Debug.Log("timedelay: "+(m_BufferedState[0].timestamp-interpolationTime));//));
_ // Use the time between the two slots to determine if interpolation is necessary*
* var length = rhs.timestamp - lhs.timestamp;
var t:float = 0.0;
// As the time difference gets closer to 100 ms t gets closer to 1 in*
* // which case rhs is only used*
* // Example:
// Time is 10.000, so sampleTime is 9.900*
* // lhs.time is 9.910 rhs.time is 9.980 length is 0.070*
* // t is 9.900 - 9.910 / 0.070 = 0.14. So it uses 14% of rhs, 86% of lhs*
* if (length > 0.0001){
t = ((interpolationTime - lhs.timestamp) / length);
}
// Debug.Log(t);
// if t=0 => lhs is used directly*
* transform.position=Vector3.Lerp(lhs.pos, rhs.pos, t);
Debug.Log(“transform.pos : “+transform.position);
//Debug.Log(” rhs.pos : " + rhs.pos +” time: " + rhs.timestamp + “t: " +t + " i: " +i +“pos: " + transform.position);
//Debug.Log(” lhs.pos : " + lhs.pos+” time: " +lhs.timestamp + "t: " +t + " i: " +i);
//var targetPos=Vector3.Lerp(lhs.pos, rhs.pos, t);
//transform.position = Vector3.Lerp(transform.position,targetPos,0.5);
//transform.localRotation = Quaternion.Slerp(lhs.rot, rhs.rot, t);
return;
}
}
}
// Use extrapolation*
* else*
* {
/Debug.Log(“extrapolate”);_
var latest:State = m_BufferedState[0];

* var extrapolationLength:Number = (interpolationTime - latest.timestamp);*
* // Don’t extrapolation for more than 500 ms, you would need to do that carefully*
* if (extrapolationLength < m_ExtrapolationLimit)
_ {
//var axisLength:Number = extrapolationLength * latest.angularVelocity.magnitude * Mathf.Rad2Deg;
//Quaternion angularRotation = Quaternion.AngleAxis(axisLength, latest.angularVelocity);*_

_ transform.position = latest.pos;// + latest.velocity * extrapolationLength;
//transform.rotation = angularRotation * latest.rot;
* //rigidbody.velocity = latest.velocity;
//rigidbody.angularVelocity = latest.angularVelocity;
}/

* Debug.Log("extrapolate!!!1 pos : " + m_BufferedState[0].pos);
transform.position =m_BufferedState[0].pos;*

* } *_

* //transform.position= m_BufferedState[0].pos;
_ //}
}
}
}
i use buffered RPC to send pos from server to client because of some bug with onserializenerworkveiw
@RPC*
*function sendInfo(posReceive:Vector3,info : NetworkMessageInfo){ *_

* var i:int=0;*
* // Shift the buffer sideways, deleting state 20*
* for (i=m_BufferedState.Length-1; i>=1 ;i–)
_ {
m_BufferedState = m_BufferedState[i-1];
}*_

* var state:State=new State();*
* state.pos=posReceive;*
* state.timestamp=info.timestamp;//tme;*
* m_BufferedState[0] = state;
//Debug.Log("state [0].pos= “+ m_BufferedState[0] .pos +” state[0].times : "+ m_BufferedState[0] .timestamp);*

* // Update used slot count, however never exceed the buffer size*
* // Slots aren’t actually freed so this just makes sure the buffer is*
* // filled up and that uninitalized slots aren’t used.*
* m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);*

* // Check if states are in order, if it is inconsistent you could reshuffel or*
* // drop the out-of-order state. Nothing is done here*
* for ( i=0;i<m_TimestampCount-1;i++)
_ {_
if (m_BufferedState.timestamp < m_BufferedState[i+1].timestamp)
_ Debug.Log(“State inconsistent”);
}*_

* //transform.position=posReceive;*

}

Perhaps not directly related to your main topic, but why buffered…? Your buffer will grow ridiculously fast and new players will receive every single one of those RPCs when they connect (they should only need the most recent)

Also, you should use code tags for posting code on the forum