How do i get the Raycast rotation?

So i am making an Island with trees with raycasting, and i would like to know how can i instantiate an object(tree) at a raycast point and raycast rotation like in Pic1. Would anyone know how to do this?


(I could not upload the picture for some reason :|)

Make sure the pivot of the tree object is at the bottom of the object. (the point where it should connect to the surface)
If you can’t modify it in a 3D modeling application you can do it in Unity by creating a new empty gameobject and placing a gameobject with the mesh as a child and modifying the child’s position.

Then in your Raycast script:

tree.transform.position = hit.point;
tree.transform.up = hit.normal;

(if you did the pivot trick, tree is a reference to the parent object you created)

If you want to use the direction of the ray and not the normal of the surface then just set transform.up to that direction vector (which you should already have when creating the raycast). You probably have to multiply it by -1 so it points to where the ray came from.