2D Platformer — Running along curves and running up walls

I’m working on a 2D platformer. Eventually I’d like to have the player be able to easily run along uneven, curved terrain and up walls, like in this diagram

I’ve got part one figured out, but having trouble with two and three?? I’m pretty new to Unity and would appreciate any advice. From looking this up online, I’m pretty sure I’m going to have to use a raycast from the player to the ground to determine his angle of rotation, but I’m not sure how to do that. Once I figure that out, I imagine I can just set a boolean called wallRunning to true if the character is rotated +/- 90 degrees and is colliding with a wall, and when wallRunning is true I’ll check if the up or down button is being pressed and move the player accordingly. Just not sure how to do the whole rotation thing :S

I would imagine you will have to learn raycasting, what I am learning for my projects.

It would probably use this sort of thing:

You would cast a ray down from your players feet and keep him oriented with whatever is under him.
I’m learning this atm so I can’t really help with the coding :confused:

Right now I’m trying to get

   function OnCollisionStay (theCollision:Collision) {
        transform.rotation.z = theCollision.contacts[0].normal.z;
        }

to work, but it’s not working at all. Does anyone know how I can improve this?

Ok, so I’ve figured out the rotation by setting my character’s transform.right equal to the normal of his first contactpoint. This gets me up the hill and onto the wall, but it’s extremely jittery and all the character’s momentum is lost. Does anyone have any ideas how I can fix this? Can this be done in unity?