I had a severe left groin pain that occurred in bed when lying on either hip, and when stepping sideways, and climbing in and out of my truck.
An xray might show possible femoral-acetabular impingement (FAI) which basically means you might be pinching (in the groin) the labrum that lines your hip joint.
An MRI might show an actual tear of the labrum, common with athletes. A money-maker is hip arthroscopy to 'trim and tidy up' your labrum. However, that might hasten the development of the inevitable arthritis....
Old people have age-related degeneration to their labrums which is why a surgeon might tell you your hip is 'bone on bone' and recommend hip replacement. (People rarely request a copy of the real surgery report but they should for their own edification.)
I had the possible FAI on my xray, however... at the time I was living with my mother who has the hardest mattresses in the world. She sleeps like a mummy on her back, but I am a side sleeper. As soon as I returned to my own home and softer mattress my pain improved tremendously. Still exists, but much much less pain.
Hello~Have you had an MRI to see what exactly is going on? It would be difficult for a doctor to diagnose without having some images to go by.
In the meantime, I would try seeing a chiropractor, you may have some pinched nerves causing spasms, if this is the case, then the chiropractor will be able to help, they can also refer you for an MRI or other x-rays that may help.