Ooops, just remembered.
replace vec_length(temp)<10 with abs( vec_length(temp) )<10.
The magnitude of the vector returned by vec_length could be negative AND large and thus trigger your routine. For example, if the velocity is -100 down, it would trigger your routine eventhough the ball is moving fast down. Using abs (or absolute value) will mean that the number will always be positive and thus only small values of temp (ie small values of velocity) should enact you're behaiviour.