They stray from the straight path.
Nocturnal insects, while flying, navigate by the moon and stars. These celestial bodies are at a significant distance from Earth, and their rays are nearly parallel. To move in a straight line, an insect must maintain a constant angle between its direction of movement and the direction to the celestial body. In contrast, the rays of light from artificial sources spread out in all directions. Thus, by keeping a constant angle relative to these rays, the insect moves not in a straight line but in a logarithmic (spiral) path.
If the spiral intersects the rays at an acute angle, the insect will tend toward the light source, and if at an obtuse angle, it will move away from it. At a right angle, the spiral becomes a circle. Indeed, observing the flight of insects, one can notice that they usually do not fly directly toward the light source but approach it in a spiral or circle around it. In reality, insects strive to move straight, but the laws of geometric optics keep them near the lamp.
Sometimes they sharply change direction, but the new direction again spirals. If an insect has chosen a course at an angle greater than a right angle, it will move in a diverging spiral until it loses sight of the light source. Such moths are not observed near lamps.