 default_distance = 20
 min_pitch = 20
 max_pitch = 50

#local vars
 autopitch_min = 0
 autopitch_max = 50
 max_distance = 70
 min_distance = 10
 transition_distance = 50

distance = distance - direction*8

if (distance < min_distance)
 distance = min_distance
 pitch = autopitch_min

else if (distance > max_distance)
 distance = max_distance
 pitch = autopitch_max

else if (distance < transition_distance)
 pitch = autopitch_min


else
 fraction = (distance-transition_distance)/(max_distance-transition_distance)
 pitch = autopitch_min + (autopitch_max-autopitch_min) * fraction
 max_pitch = 90
 min_pitch = 40

endif 
endif
endif


#edge rotation
fraction_x = edge_distance_x/32

if (edge_distance_x > 0 and edge_distance_x < 32)
 yaw = yaw - (1-fraction_x)*3
else if (edge_distance_x < 0 and edge_distance_x > -32)
 yaw = yaw + (fraction_x+1)*3
endif
endif

#move camera behind avatar when avatar is moving
if (avatar_speed > 0)
  yaw = yaw * 0.9
endif