All good answers, but one thing that I swear by, and I don't use any other method and it works in minutes.
You can do this if you are on a mounting block, or just on the ground. If you have ahorse that stands still for mounting, but walks off when you get into the saddle I would recommend you training your horse from a mounting block.
Anyway, climb up on your mounting block, or get in position on the ground. Guide your horse up to you by pulling on the rein closest to you. If he takes a step forward without swinging his hind end away, stop and praise for each step. If he swings his hind end away, simply pull his head to your right, and wave him back over with your left hand. This will re-align the horse to be mounted. Then you repeat to get him closer. Any effort on the horse's part to stand still or to not move away, just stop for a moment and love on him. The second he goes to walk away, or move his hind end away, pull his head back and swings his hind end over with your arms, or if you have a dull horse use a whip to wave in the air.
This takes seconds, and it is very clear to the horse that the only place of peace is next to you, parallel to the mounting block, and standing quiet.
If your horse understands, but moves when you go to put your foot in the stirrup, do not mount. Repeat until he stands quiet.
Be careful not to pull down on the bit, or punish the horse for moving with the bit. Simply use it as a re-direction.
If this does not make enough sense, I'd be happy to do a short video for you.
In riding, a horse's energy is like a river- guided by the banks but not stopped by them.