calculate the speed of the object