Listening to other people do it. Just immerse yourself in others' music. Listen to all varieties and styles and pay attention to what the pros do with their melodies. Pros don't just write a melody entirely of quarter notes. They sex it up with rests, syncopation, fluctuating note duration, the occassional leap, etc.