default_distance = 20

#if the mouse wheel has moved
if (direction ~= 0)
 distance = distance - direction*8
 if (distance < 20)
  distance = 20
  min_pitch = 5
  max_pitch = 50
  pitch = 5
 else if (distance > 70)
  distance = 70
  min_pitch = 60
  max_pitch = 90
  pitch = 90
 else
  fraction = (distance-20)/50
  pitch = 15 + 75 * fraction
  max_pitch = 90
  min_pitch = 5 + fraction*55
 endif 
 endif

#if the mouse wheel hasn't moved (default on camera mode switch)
else
 pitch = 90
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 