Friendly fire can occur when a character attacks with any ranged weapon requiring an attack roll, including certain ray and orb spells.
If the character’s attack roll comes up a natural 2, then examine the area between the attacker and the desired target. Within a 60-degree cone spreading out from the attacker, the ally nearest the intended target is then the subject of friendly fire. If no allies are within that cone, friendly fire does not occur.
The ally which suffers friendly fire will automatically take damage from the attack just as if the intended enemy had been successfully hit (although of course there may be differences regarding damage resistance and other circumstances.)