# Trying to instantiate object at ray hitpoint, at the angle of the hitpoints' normal.,Trying to instantiate object rotated towards normal of raycast hitpoint.

Hi all,
I’m trying to instantiate an object at the mouse position using a ray from the camera. I have this all working fine apart from the rotation. I’m trying to get the object to rotate facing away from the terrain it’s instantiated on, like it’s jutting out. I’ve seen many similar posts answered vaguely with the use of LookRotation, and one of it’s parameters being the hitpoint.normal, though it’s never explained what else the parameter needs, or what needs to be done with the quaternion afterward.

I’ve tried using all assortments of direction vectors in this function, but none have given the desired effect, Ive come close a few times but I’m at my wit’s end.

Any help would be appreciated, here’s the function below.

//Function to calculate the Quaternion of the normal angle outward of a rayhit

``````Quaternion getCollideAngle(RaycastHit rayhit)
{
Quaternion CollideAngle = new Quaternion (0, 0, 0, 0);

//Get the lookat from the rayhits normal as a direction vector
CollideAngle = Quaternion.LookRotation(rayhit.normal);
Debug.Log(rayhit.normal);
return CollideAngle;
}
``````

,Hey all,
I’m trying to build a game where puzzles are based off a mechanic similar to the breath of the wild cryogenesis gadget. In this particular case im trying to instantiate an object at a raycast hitpoint, with the object rotated towards the hitpoints normal. I can’t seem to get this to work but i’ve gotten close to the desired effect multiple times. Here’s my code so far, any help would be greatly appreciated:

//Function to calculate the Quaternion of the normal angle outward of a rayhit

``````Quaternion getCollideAngle(RaycastHit rayhit)
{
Quaternion CollideAngle = new Quaternion (0, 0, 0, 0);

//Get the lookat from the rayhits normal as a direction vector
CollideAngle = Quaternion.LookRotation(rayhit.normal);
Debug.Log(rayhit.normal);

return CollideAngle;
}
``````

I’ve tried multiple times to plug a direction vector into the first parameter of LookRotation, but have had no luck with any direction vector yet.

Try this:

`transform.rotation = Quaternion.FromToRotation(Vector3.forward, normal);`

AHAH, Vector3.up works using this function. Thank you for your comment.