C# Cant get correct speed value from gameobject

Hi

I am trying to save some bandwidth in my network game, idea was to calculate the speed of gameobjects to play correct animation (idle, run, walk) rather than broadcast the current animation state over network.

When I calculate the speed of my local character, I get stable/correct values.

Around 0 for idle, around 3.5 for walk and around 9.5 for running.

But when I try to calculate speed of objects controlled by other clients. I start to get real wierd values.

I get speed values around 0 & 6 & 7 & 14 for walking. And 0 & 20 & 40 & 80 for running.

I think it is becuse of the “lagg” the calculated speed get really wierd?

How can I fix that?

EDIT
I Guess it is possible to either do some kind of movement prediction or compensate for the lag? Or is that not the way to do it? Please give advice or point me in right direction.
<-EDIT*

Here is the code I use:

`

using UnityEngine;
using System.Collections;

public class NetworkAnimationSync : MonoBehaviour {
	
	
	public float speed = 0;
	
	Vector3 _prevPosition;
	
	// Update is called once per frame
	void Update () {

			if(!networkView.isMine)
			{
			
				Vector3 vel = (transform.position - _prevPosition) / Time.deltaTime;
				
				speed = Mathf.Sqrt(vel.x * vel.x + vel.y * vel.y + vel.z * vel.z);
			
			if(transform.position == _prevPosition)
			{
				animation.Play("idle");
			}
			else if(speed > 3 && speed < 5)
			{	
				animation.Play("walk");
			}
			else if(speed > 9)
			{
				animation.Play("run");
			}
			
			_prevPosition = transform.position;
			
			Debug.Log(speed);
				
			}
		}
	}

`

Guess my other alternative is to send RPC calls with the animation states :confused: