Angle Based on Terrain

For my game, I have following type of terrains.

Static Terrain Creation Programmatically

I want to set angle of my main character body based on terrain curve.
At present I am working on raycasting to achieve this but didn’t get full success.

So what is the preferred way to solve this problem?

i used some code from this great article:

the code not completed but the most imported parts are there. works great for me…