Hello all,
I am getting this error only on rare occasions (so harder to figure out where).
It shows up inside an Update loop, on this line:
transform.position = Utils.MoveTowardsPlayer( transform.position, activeMagnetZone, activeMagnetSpeed );
The MoveTowardsPlayer function is here:
public static Vector3 MoveTowardsPlayer( Vector3 from, float magnetZone, float magnetSmooth ) {
if( magnetZone == 0 || magnetSmooth == 0 ) return from;
Vector3 to = Dispatch.PlayerPos;
float distance = Vector3.Distance( from, to );
if( distance == 0 || distance > magnetZone ) return from;
// Above line originally was
// if( distance > magnetZone ) return from;
float smooth = magnetSmooth;
smooth *= (magnetZone-distance)/distance;
return Vector3.Lerp( from, to, Time.deltaTime * smooth );
// Alt method
// return Vector3.SmoothDamp( transform.position, magnetPos, ref magnetVelocity, magnetSmoothTime );
}
So, the only place I suspected could cause the error, was if distance is 0, so I am now checking for it as well - but I am not sure this is the reason, as I would have expected a “division by zero” error.
Can anyone help in figuring out which is the cause for the error?