Some old code I picked up somewhere, works a treat though.
Place this after when tracing to the ground so you get the returned normal of the surface. No need to use temp you can use another defined vector.
c_trace(tracing to ground...);
temp.tilt = 0;
temp.roll = 0;
temp.pan = -my.pan;
vec_rotate(normal, temp);
temp.tilt = -asin(normal.x);
my.tilt += 0.1 * ang(temp.tilt - my.tilt);
// play with 0.1 for speed of tilting
my.roll = 0;
Hope this helped.