Have you been coughing a lot as a result of a recent throat infection? That could cause muscles around your lungs to strain and consequently the pain with each cough. If that's the case, try suppressing the cough for now with some (1 or 2 doses) of cough syrup for immediate relief and try taking a course of antibiotics, (eg. Tab Azithromycin (500 mg) once a day for 5 days). Muscle strain is most likely the scenario.
Next Steps
Find comfortable positions to sleep. Hold a pillow against the right side of your chest when coughing. Try some over the counter pain relief meds like Ibuprofen (400mg), (maximum twice per day), stay hydrated and avoid strenuous activity. This should give you relief.
Health Tips
However the fact that you mentioned pain with changing position warrants further evaluation. It could be pleuritic pain. Please report any kind of shortness of breath, even if mild, while lying supine. See a doctor if the positional pain is severe, along with shortness of breath, or if coughing blood, or if high fever, rapid heart rate, skin turning blue, or if pain shoots down your arm. If your lungs sounds are abnormal on the stethoscope, you would need a chest x ray and your oxygen saturation will have to be seen with a pulse oximeter, you might even need an ultrasound if any gallbladder issue is suspected.