Originally Posted by: MglamboI was improvising to a backing track song - Morning Dew - in D major. It obviously resolves to the D.[/quote]I'm not familiar with that song. Can you post a link?
Also, you mention that it resolves to D. How did you determine that?
Originally Posted by: MglamboWhen playing the D major scale if I hit the C# note it sounds awful.[/quote]That's going to create the sound of a D major7 chord. Also, the C# would be part of an A major chord as the V chord if the song is in the key of D major. Is there an A major chord in the song? If so, have you tried to target the C# when it happens? If not, then maybe you aren't in D major.
[quote=Mglambo]So I would flatten it to C and it sounded great. Is this perhaps because the song is in D mixolydian mode? Therefore the key of G major?
Maybe so! It might be in G, or it might be a modal piece in D mixolydian. It depends on the context of the whole song or chord progression.
[quote=Mglambo]And if so how would one figure that out? Just by ear or trial and error? Thanks in advamce!
You accomplish that by considering all the chords & notes in the song & when they occur. That's how you determine the key signature & which scale or mode to use & how & when to target chord tones.
This is a good place to mention my collection of tutorials on improvisation. You might be familiar with some of these concepts, but it might be a good idea to review & work through all of them.
https://www.guitartricks.com/collection/learning-to-improvise
Hope that helps!