Actually this is not a good idea to do it this way, becasue then you are calling vec_dist for every render of every entity. This is going to be sloooww
Better to use a loop in an action like this
while(1)
{
if vec_dist(my.x,camera.x)>dist && my.material!=newmat
{
chnage material to newmat
}
wait (1+random(5)*random(2)); //or whatever
}
this way you only call vec_dist once in a while for each entity...