you could do a trace instruction upwards to look for a roof every so often and create a global var ...say var im_inside=0; and if trace hits a roof above you can change im_inside=1; , in the while loop that controls your rain put an if statement like so