How did infantry fight off both light and heavy cavalry?

by MrAlbs

Aside from staying away from flat grounds, what tactics have infantry based armies used to counter the strengths of calvary?
So far I have heard using spears (but wouldn't the horsemen simply use spears themselves?) and projectiles like javelins, slingers and archers (but wouldn't the cavalry be able to charge towards them unless they were protected by terrain all around?)
I'm interested in both Ancient and Medieval tactics here.

BreaksFull

The time-honored tradition was the shield wall, where the infantry lined up with their shields and held their spears forward. No cavalry is going to successfully run into a wall of shields and bristling spears. The trick for the infantry is maintaining discipline, if the wall breaks the battle is lost. And a hundred thundering knights galloping towards you in full armor is enough to break the resolve of less-experienced or trained men.

This later gave way to pike squares, which were square formations of pikers -often with marksmen in the center, protected by the pikes.

riosmundo

I would like to chime in on this. Early modern warfare was more psychological than physical. Horses don't like to run into things and will not charge into a dense formation or spears like you see in Lord of the Rings.

If the infantry do not break the horses will rear up and stop. If the infantry do break the horses will charge into the gaps made by men running.

In short it was a giant game of chicken.

Source: My early modern military history class

RedditoryInstincts

The ancient Macedonians used 18 foot long spears, much longer than any cavalryman would wield. This was compounded by the formation, a phalanx with good discipline had FIVE spears between you and their front soldier, per column.

MushroomMountain123

Animal behavior also comes into play. Horses are not tanks or humvees, they have a mind of their own, and one of their absolute basic instincts is not to run into pointy things. Part of this has to do with physics. Horses are much heavier and move much faster than humans, so they have a stronger instinct to avoid running into things. A human running into a wall would hurt a lot, maybe break a rib or two. A horse running into a wall would break the neck, and leave a sizeable indentation in the wall. Since one of the big advantages of mounted combat was that you could charge with massive momentum, the idea was to stop the momentum in it's tracks by causing horses to disobey the rider and slow down or turn in a different direction.