Are there any tricks that help make melodies besides just experimenting until you find something that sounds nice?
OK lets see hints for Melodies...
Patterns are key. If you write a melody in a theory exam they will give you an extract from which you can repeat certain patterns.
After a cadence you need a rhythmical sequence. That is rhythm that is repeated for at least two bars. This a just a repeat of the rhythm the notes need not be identical.
Know your cadences.
Try to end on the tonic
If you use a pause in the middle of a melody to indicate a cadence try to use cadences that do not end on the tonic. It is poor to give the feeling of ending in the middle of a melody.
Jump only to notes in the chords. Do not jump two notes in a row. When you jump up as a general rule go down after a jump up. Go up after a jump down
Try to use melodic minor shape if you go up from the sixth to the seven steps (In minor keys) If you go down from that remember what needs to be lowered
Leading Tones ALWAYS needs to resolve.
In the passage you are given take note of the form of the notes. That means if the notes go up and down in a wave form mimic it. If the notes seems more like runs mimic the runs.
It is also critical that you know your basic chord progressions. They will help you determine which chords you will use.
Remember your articulation.
Depending on the method you are learning you may need to take note of which instrument you are composing the melody for. ABRSM for instance requires you chose a instrument and compose the melody for it.
If this is true in the theory you do you will have to learn the scope of the main orchestral instruments. Also things like how up and down strokes are done in violin music is also important.
If your method requires you to make a vocal arrangement then you have to know that there is a limit to how singers can jump and they also have specific ranges among the different types of singers.
Ooooooh there are so many hundreds of tricks and tips that you can use. I'd refer you to my blog, but for now let me give 3 simple ideas that I love to utilise, and go to regularly. These apply to melody-writing and to writing music in general.
Make the music reflect the intended message
Using text or words, simply write the melody to imitate the natural flow of the language. Take "I love you and I don't want to let you go". Rhythm-wise there's a natural flow to the words - "I love you, and I don't want to, let you, go" or alternatively ""I love you, and I don't want ,to let you go". Either way you have a rhythm right there. Now with the pitches it's all about what you want to convey, and potentially the style of music. A lament might start high and get low, a climactic Opera song might end on a climax - "...Leeeeeet you gooooooooooooooo" queue trumpets, fat lady, curtain fall, great success. Point is, the intent dictates the music, meaning a melody is just a set of criteria put into concrete form :)
Have a creative constraint in place
Many of my compositions and melodies have stemmed from trying to do a certain theoretical idea. Studying the theory behind modulation, a neapolitan 6th, the tristan chord, or the diminished 7th has led me to write the main goal of the part, and then everything else is just filler around it. once you have 4 notes and a rhythm, the rest is potentially just about what fits with them.
Get bored of your own music
It's better to write a stifled idea than it is to remain stifled. And by this I mean that if you're having difficulty with a melody, just write a cruddy melody that you're not sure of, because that gives you a starting point. If it's clearly not working, then great news! You can tell that it's not working! It's when you start to enjoy your melodies that the danger comes...
Cynicism aside, knowing what you don't like about your music allows you to affect change, to go towards the light and scrub the note heads till they are as shiny as they can be. over time you will find common elements to your writing that you can focus on fixing, or embracing depending on your viewpoint. Eventually you might find there are no specific errors yet you still find your music boring.
At this point it's time to be more daring once again. what happens when you go over the top, break the rules, rock the boat, similarly phrased metaphor? If you make mistakes at this point you have a sensitivity for them, but more importantly, you will begin to learn when it's OK to break them.
In this method you can continually grow and learn without becoming generic. Your melodies will be uniquely yours with a well founded ear behind them.
Sorry to ramble on that last one. Being a Prog fan I say in 24 minutes what could be said in 3 :/
There are a number of different techniques you can use depending on the genre of music, instruments used and style of an individual piece. For context, I'm primarily a bassist, but I play a bit of guitar too. There are two main methods for overall songwriting I use:
1) Riff Writing. This will usually start with a bassline or guitar part I've come up with (I'll cover later, I suspect this "coming up with" is that your primarily getting at) which will often form the most melodic line of my piece.
2) Chord Progressions. Instead I may start on guitar and write a nice group of chords and then fit something to that.
So how do I decide what I'm going to play?
Mostly it's a question of knowing scales, knowing what intervals within those scales sound good, and ultimately just spending alot of time playing to know what sounds good and what doesn't. In a more improvised form there are also little licks or ideas that I reuse if I particularly like them, even just a little semitone slide or interval can be useful to throw in.
Sometimes I'll have an idea in my head that I'll then take to my instrument and try out, adjusting as appropriate or ditching it if it doesn't quite work out (annoyingly frequent result). Others I'll just have a drum beat on and am playing around in a given scale, or have a backing track of chords playing and improvise until I find something I like. There is a sort of middle ground where I may have a sort of "grand plan" for what I'm trying to write which I then improvise on.
So by combining a knowledge of chords and knowledge of how key signatures work you can write numerous musical ideas. The best are the ones that I record, leave for a week, come back to and still like. This is often few and far between.
So to answer your question as succinctly as possible, in my experience melody writing is primarily a sort of "estimated guess". You know what theoretically could sound good, then tweak it from there to find what you want. However this is obviously not an exhaustive list. There will be plenty of other answers and methods people will use, and some people are able to just jot down a melody and it turn out to be amazing. I'm not quite able to do that.
I have a couple of examples currently on my soundcloud where I used each of the two methods above if they would be of use. Both are bass-orientated melodies, but one where I started with the guitar chords and wrote from there, and another that I just jammed until I had something I was happy with. My guitar playing is poor, but it may help illustrate my point. Of those up, "Test" was a set of chords I played bass over, and "Thorium" was a bass line I came up with by just playing in C# minor for a while.
There isn't a systematic way to write strong melodies. You have to know what you intend of each specific melody.
One thing that you can do is listen closely to songs you enjoy and figure out what makes their melodies work. For example, I really like high energy electronic music, so oftentimes, when I listen to it, I try to discern how each song pushes its intensity levels higher. One of my favorite songs, Granite by Pendulum, has a melody that's played with guitars that have very thick effects applied to them, giving them an incredibly forceful sound. The melodies they play are repetitive and deliberate, giving the song an angry type of energy, but they also have large jumps, making the energy exciting as well.
By listening to songs carefully and critically asking yourself how their melodies produce their various emotions, you'll figure out which rules of thumb are best for the types of music you want to write.
Take a look at Melody in Songwriting, by Jack Perricone. There are lots of aspects of melody that I understood intuitively but couldn't articulate to my students until I read Perricone's descriptions, which made them explicit.
Here are screenshots from the table of contents:
I don't have to add a lot, because other users have said it, but here is another book suggestion, Figuring out Melody by David Fuentes. You can find it here. My advice is to sit down (ideally) every day and sketch a melody. One melody can seem to you like "meh, not really interesting" one day, but maybe after few months it could catch your interest when you revisit your sketches.
Others have already laid out good practical and technical advice, so my very general answer is that the trick (if you can call it that) is to be inspired.
In my experience, if you sit down, whenever, and try to come up with a bunch of riffs, you can write a lot of them but you're going to think most of them are lame, unoriginal or otherwise "uncool". Now, if you did the same thing in a moment of inspiration, you might come up with the exact same riffs, but now you think those riffs sound good.
How to get inspired? Who knows, man. As for practical advice (if you're anything like me): I get inspired at any time, any place, and with it comes an idea of a riff, so if I'm not at home, I record myself singing that riff into my smartphone so I can work it into a song later on. (I tend to forget the idea unless I record it or write it down immediately.)