Friction always opposes the direction that the motion is taking place in.
Truly understanding motion and friction requires an understanding of atomic physics and the electromagnetic force. First, no object is perfectly smooth at the atomic level. While it is hypothetically possible to create perfectly smooth things in a laboratory (and this may be possible soon, and lead to significant improvements in various technologies) in the natural world, even the smoothest object would appear ragged if viewed under strong magnification, such as an electron microscope.
These imperfections causes all objects to have inconsistencies at the atomic level, which leads to collisions and obstructions when two objects interact.
When these objects interact, their atoms don't really "touch". Instead, they levitate, in a manner of speaking.
All atoms are surrounded by a cloud of electrons, so the overwhelming majority of the outside of any atom has a negative charge. This means that any two atoms will, on average, repel each other when they come into contact. This is the same reason we're able to stand on the Earth instead of falling through it; the atoms in our bodies are repelled by the atoms in the Earth, at the atomic level.
When those jagged imperfections between two objects come into contact, friction is produced. Friction causes some of the velocity of the object to be fragmented in different directions, or absorbed as heat. For example, if an object traveling in a straight line strikes another object at a 45 degree angle, the resulting free-body diagram will show that much of the original velocity is deflected or lost.