Hello. Im trying to make two object making distance. one is controlled and one will go faster if the object is catching up. Im trying to use the magnitude but it seems it doesnt slow down even if the gap between the two is close. it just stopped
var speed:float = 3.0;
var slow:float=1.0;
var other : Transform;
var far = 200.0;
function Update()
{
if (other) {
var sqrLen = (other.position - transform.position).sqrMagnitude;
if( sqrLen < far)
transform.position += Vector3.forward * Time.deltaTime*speed;
else
transform.position += Vector3.forward * Time.deltaTime*slow;
}
}