Sleeping on moving vehicles packed with people is a skill. It can be learned. Some people are naturals at it, but most have to practice a few times before they get good. There are techniques which help you get better at it more quickly.
If you're an independent traveler on a budget, this is a skill you'll want. Spending a night on a train or a bus saves you the money you'd spend on a hotel or hostel. It also means you can hop on a bus for 12+ hours, if you really just want to get from point a to b, and that's the simplest and cheapest way to get it done.
Like a lot of things in life, there's no one "right" way to do this, but I do know a few tricks that work for me. I'm going to be writing this the most common (and next-to-hardest) situation in mind: something that has you sleeping in a single reclining seat with people next to you. I'll say "bus" throughout this next example, but this applies equally to many trains, most airplanes, and some boats.
Getting to sleep easily for me is all about routine. If I can do all the little things that signal to my body that it's bedtime, it's a lot easier to sleep in something uncomfortable and un-bedlike than if I've just been running around in circles drinking red bulls. I don't drink caffeine (or taurine) right before bed, so I don't do that if I'm about to sleep on a bus. I usually brush and floss my teeth before I go to bed, so I try hard to make sure I do that before going to sleep on a bus. Learn to do this with just a water bottle and a place you can spit without making anyone mad, and you'll go far. If you have a bathroom with a working sink on the bus, take advantage of it. To do so, you'll need your toothbrush, etc. in your carry on bag, so decide when and where this will happen before you check any bags.
This next trick might seem a little extreme, but it works for me. I never recline my seat unless I want to sleep, or unless the seat is just leaning forward too far (Japanese Shinkansen, anyone?). This means, after a few times, my body associates a reclined seat with sleep, and drifts off more easily when I lean back. Also this means to really wake myself up in the morning, I just return the sight to its upright position.
I tend to sleep more easily in the dark. Light (especially sunlight) wakes me up very quickly. So, before I sleep I blindfold myself. This keeps me asleep whenever we go through a bright town or the lights come on. There are cute little eyemasks for this purpose everywhere, but I just tie my bandana around my eyes. As a warning, with either method, friends will sometimes find this kind of cute and hilarious, and will show you the pictures they took of you while you slept the next morning. You'll get used to it.
Next is simple comfort. Most of this is mental, these seats aren't going to be very obliging. If you obsess about the one thing that's poking you or doesn't feel right, shift a bit and concentrate on the parts that are comfortable. An inflatable neck pillow can help, though I don't have one. What I usually do is just make sure I'm not too hot or cold, and then use something as a cover, usually my jacket. I'm used to having a cover on a bed when I sleep, and this mimics that enough to put me to rest.
Know what kind of noise level lets you go to sleep, and get it. I sleep best with no noise, or maybe some white noise like rain, so I use earplugs. I personally prefer swimmer's rubber earplugs to the cheap foam kind, but try a couple different ones to see what works best for you. If you're like some of my friends who usually go to sleep with a TV on, get some noise-blocking earbud headphones. They don't have to be fancy, the $6 pair with the fitted rubber buds work almost as well as the fancy electronic noise canceling types, and are usually a lot less conspicuous. A pair of those and your mp3 player (or anything else that does music) should do the trick nicely. Make sure your music device is tucked away somewhere that's not obvious to any would-be thieves.
While we're on the subject, make sure your belongings are safe. On buses, you can usually check them into the compartment below. Trains are trickier. If you're on a bunk, there's sometimes a space underneath you can put your bag that can't be accesed without lifting up your bunk. if you're on a top bunk, just sleep holding your bag or with it possibly tied to you somehow. It's actually a lot easier and more comfortable than it sounds. On airplanes, rest easy. With that many flight attendants hovering around and the paranoid air about any kind of security, you can just about dangle half an electronics store and jewelry shop across your lap and wake up with all of it there in eight
Finally a few specific notes for airplanes. Do yourself a favor and do not watch the movie unless you'll have enough to time between its ending and half an hour before landing to sleep. If you're on an airplane ride long enough to sleep on, chances are good you're making a big time zone change. As soon as you board, change your watch to the time zone you will arrive in, and try to mentally shift to that time. The meal schedule won't always oblige, but just think of whatever meal it is as being oddly early or late (or just think, "hey! breakfast for lunch!"). And sleep no matter what. Think of it either as a daytime nap or you nighttime sleep, whichever makes more sense depending on the current time in your destination. These, combined with holding out until bedtime to really sleep in your destination will help prevent jet lag.
The bad news? None of these tricks will work the first time you try them. It took me two straight nights on buses for them to really solidify. the first night I barely slept, and then the next night I was so exhausted that I slept like a log. I don't really recommend such a crash course (though I will say three consecutive nights on transport will make you an expert at falling asleep just about anywhere). My point is, that it will be a few times before you'll be able to drift off normally on these things. Like I said in the beginning, it's a skill, and it will take practice. Best of luck, and sweet dreams.