Download

Align mesh to ground's normal

Hello everyone, I am working on a way to place foliage at run-time, everything is going fine, but I can’t seem to get my meshes to align to the slope/normal of the floor underneath it. I am doing a line trace from where the mesh is, to underneath the mesh, but nothing I’ve tried has worked. I am looking for a way to get the rotation at which the mesh should be rotated to to be aligned with the floor. I’ve done tons of searching on the forums and Answer-hub, and all I’ve seen is one solution for aligning a hovercraft, which doesn’t really help me because I do not use torque, I use rotation.

If anyone can help, that would be great!

Bumping this, isn’t this some simple vector math that I don’t know about?

Alright everyone, I’ve got this figured out, though at some slopes it can be off by a max of 15 degrees due to normal not being consistent with angles :\

Here is a screenshot, I am line tracing from 300 units in front of me, to 300 units in front of me and down a bunch.

9e1cab741f5c57a0c0231dc12b6adf886d1d47e4.png

The reason I am subtracting Z by 20 is to make up for the ~15 angle innacuracy, if I don’t subtract by 20, then you can see the bottom of the object a bit.