Creating a pleasent or unpleasent melody (on purpose) has always been a partly intuitive question, I´d say. Not even classical counterpoint offers a formula to create a main melody. Instead you are given a Cantus Firmus, an already given melody, and what you learn is to make second voices that fit its implied and possible harmonies, not to make the main melody. In classical counterpoint, you do not think in the division rhythm, chords and melody, but what is called Species, that is movement of voices in a linear perspective, e.g. one playing in whole notes, another in quarter notes. So every voice is considered a melody. The focus is on intervals and the relations between consonances and dissonances and not chord blocks. Harmonies arise from interaction of voices from "below" rather than being smacked down from above by a chord instrument. Chords extensions like a 6th, 7th or 9th are always dissolved into consonant triads.
Me and my bandmate´s music is all melody driven. However inventing them is not a theoretical issue, but very intuitive. I am pretty messed up in theory, but when it comes to melody, it is a spiritual matter, I have no idea how they arise, but I recognize my inspiration from classical music, folk music and modern music I have listened to all my life. Sometimes it ends up in rather freaky combinations, e.g. this tune where you will hear a paganistic melody written for bagpipes in combination with Wiener-classical aspirations and a synth bass that moves in phrygian and locrian moves inspired by Industrial. So it is basically a multimodal mess from a theoretical perspective, yet we think the intuitive relation between the melodies bind the mess together. Judge for yourself. Our melodies simply arise from listening and listening and listening to different kind of music: modal, tonal, western, eastern etc. Therefore that is the best advice I can give. Listen and hum your own out in your head. You got them all in there. Hope these thoughts can inspire you further.
Kindly
Gothi
Tribe of Hofund