"Look rotation viewing vector is zero" error

I have some smooth look code that spams this error. It basically makes an object look in the direction a rigidbody is moving.

void Update()
{
	if (target)
	{
		if (bSmooth)
		{
			Quaternion rotation = Quaternion.LookRotation((transform.position + target.rigidbody.velocity) - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotation , smoothSpeed * Time.deltaTime);
		}
		else
		{
			transform.LookAt(transform.position + target.rigidbody.velocity);
		}
	}
}

The error is this line:

Quaternion rotation = Quaternion.LookRotation((transform.position + target.rigidbody.velocity) - transform.position);

Basic arithmetic…

(transform.position + target.rigidbody.velocity) - transform.position

(A + B) - A = B

So if B is a zero length vector (no velocity), then the function LookRotation will be mad at you.

I got similar issue and it was to do with i didnt declare what the OBJECT tag was so it dodnt find the v3.look rotation… Are u doing similar to find your object to mouse?