Instantiate based on RaycastHit.normal

Im working on a weapon script, in javascript. And im trying to implement some particles to be instantiated where the bullet/raycast hits. I have got the position of the particles working fine. But im having trouble with the rotation.

The problem is making the instantiated particles to be based on the normal direction of the surface it hits.

So i tryed to use RaycastHit.normal, but its Vector3. And the Object.Instantiate rotation is Quaternion.

Do i need to convert the Vector3 value to Quaternion, if so how? Or is there another way to achive what im trying to do?

Yes, you can create a rotation which would make the object point in the direction of the hit normal using the Quaternion.LookRotation function. It does exactly what you need.


var startPos = hit.point;
var startRot = Quaternion.LookRotation(hit.normal);
Object.Instantiate( particlePrefab, startPos, startRot );

The particle system's forward (z+) direction will be pointing along the hit normal vector.