checkdistance func