function avoid_obstacles()
{
vec_set (temporary_distance.x, camera.x);
temporary_distance.z -= 50; // sets a position closer to the feet of the player; 50 = experimental value
distance_traced = c_trace (player.x, temporary_distance.x, IGNORE_ME | IGNORE_PASSABLE); // trace between the player and temporary_distance
if (distance_traced == 0) // no obstacles on the way?
{
my.alpha = minv(100, my.alpha + 3 * time_step); // then increase player's alpha up to 100
if (player.alpha == 100)
{
reset(player, TRANSLUCENT);
}
else
{
set(player, TRANSLUCENT);
}
if (camera_distance < my.skill40) // if the camera got closer to the player
{
camera_distance += 1; // restore the initial camera_distance slowly
}
}
else // obstacles encountered?
{
distance_traced -= 2; // then bring the camera 2 quants closer to the player!
my.alpha = (distance_traced / (my.skill40 + 1)) * 100; // decrease player's alpha; don't allow a division by zero
camera.x = player.x - distance_traced * cos(camera.pan); // place the camera behind the player
camera.y = player.y - distance_traced * sin(camera.pan); // at the new distance given by distance_traced
}
}