I have this object that is getting it’s orientation from the normals below it and I was wondering if there is a way to smooth the interpolation out?
I know I can apply smoothing on top of that rotation but I was wondering if anyone had tried interpolating between the neighbouring faces?
The normal that’s returned by a raycast will always be a “faceted” normal as it’s the actual surface facing. However it’s pretty easy to sample the angle of the underlying mesh’s vertices to get a smoother angle, assuming your mesh is smoothed (which it appears to be). No need to use SphereCastAll or multiple ray casts, though that’s a common way to do it too to handle moving between meshes.
Unity’s documentation even has an example implementation of exactly what you’re looking for:
Hey thanks guys! Sorry, now looking at the gif again the geometry is a little misleading, it is smooth, it just has different coloured faces.
What Bgolus mentioned was exactly what I was looking for though! Thanks mate!
Lookin’ Cool!
P.
Hi, the result looks good but I don’t really understand how barycentricCoordinate really works.
Does it only work with a mesh collider because I’m trying to replicate the same smoothness but on a terrain surface. I use Quaternion.Lerp but it’s really not as smooth as what I’m seeing on petey’s gif.
I tried the example that was given by Bgolus with a simple sphere and I get this error when I rollover the sphere with the mouse…
IndexOutOfRangeException: Index was outside the bounds of the array.
All I did was copy the code from the unity doc on a camera and put a mesh collider on the sphere.