I would like to rotate an object to match its ground. So i cast 3 Rays (at the corners) to calculate the normal of the plane below.
Now i need to rotate the object accordingly but keep the y rotation (so in which direction it "faces") so just setting transform.up = normal does not work.
I thought i could just use the dot product between the transform directions to rotate it (so xRotation = Vector3.Dot(normal, transform.forward) for x and zRotation = Vector3.Dot(normal, transform.right) for z) this should be the angles between the normal vector and the right/forward vector. But as the result my object just faces the sky that way to the idea is completely wrong.
Do you know how i should proceed ?

