NOTE (edit): I WAS WRITING THIS BEFORE RAYC's POST ABOVE IT CAME IN. SORRY IF IT REPEATS SOME OF HIS SENTIMENTS...
You should also know that in most cases, you do not want the bass to double the melody line, except for brief hooks or maybe a signature riff.
In the simplest function, the bass usually plays the root of the harmonic structure, although it often also moves to the fifth or plays a linear passing sequence that takes it to the next chord. It also does this in a way that outlines the key rhythmic element of the groove - so for instance, in a shuffle the bass line would tend to have a syncopated triplet feel.
Now, in good songwriting, in most cases the bass would not double the melody, because that would mean the melody is centered around the roots of each chord, which frankly, tends to sound pretty lame or, at best, boring. Plus if the bass plays the melody, it is ignoring its function of reinforcing the groove.
That doesn't mean you can never do it. For example, let's take the classic Meters tune: Cissy Strut. If you don't know it, take the time and the 99 cents and download it from i-tunes, as it will help you to understand the point. There is a lot of doubling of the bass line with melody there, but notice that this works because this song is a funk/jazzy instrumental rather than a song with a lyrical melody.
Now, take another example - say Elvis singing "Can't Help Falling in Love with You" - a typical 12/8 50's-60's style ballad. Try recording this song with you either singing or playing the melody, and then having the bass play the melody too. You'll notice it doesn't sound right, because no one is taking care of the business of anchoring down the roots of the chord changes. Now switch to just playing the roots of the chords every dotted half-note, and all of a sudden it sounds much more like music.
The best thing to do is listen to commercial recordings you really enjoy in the style of music you are trying to emulate. See how the bass functions within that style, and try to imitate that.
The other thing you should be working on is ear training. Try to pick out melodies that you can sing in your head on your instrument. When you get the hang of that, try finding the right chords that go with the melody. With practice, your hands will become extensions of your ears - whatever you hear, you will be able to automatically play. Yes, it takes some time, but there is no real shortcut to becoming a real musician - assuming that is your goal.
Note: AndyK12's post is also a very good explanation.