• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualBacterius

Posted 15 September 2012 - 09:49 AM

Anyone know how to get the angle of the surface from a raycast?

The angle of the surface is fully encoded in its surface normal - wouldn't the raycast return the intersected object and hence its normal? You probably only care about the inclination angle (not the azimuth angle which exists in three dimensions, which describes which direction the surface is "pointing towards" horizontally - like a compass placed on a horizontal surface, if that makes sense). In two dimensions, it's simple - your inclination gradient is just rise over run -> normal.y / normal.x so the angle is arctan(normal.y / normal.x) with some trigonometry. In three dimensions, it's more complicated but you can convert your normal coordinates to spherical coordinates and extract the inclination angle (usually marked theta) and go from there.

### #1Bacterius

Posted 15 September 2012 - 09:48 AM

Anyone know how to get the angle of the surface from a raycast?

The angle of the surface is fully encoded in its surface normal - wouldn't the raycast return the intersected object and hence its normal? You probably only care about the inclination angle (not the azimuth angle which exists in three dimensions, which describes which direction the surface is "pointing towards" horizontally - like a compass placed on a horizontal surface, if that makes sense). In two dimensions, it's simple - your inclination angle is just rise over run -> normal.y / normal.x. In three dimensions, it's more complicated but you can convert your normal coordinates to spherical coordinates and extract the inclination angle (usually marked theta) and go from there.

PARTNERS