- Home /
Instantiated bullet hole has wrong rotation
Hello,
I have this script that Instantiates a bullet hole when a raycast hits something. The problem is it Instantiates on wrong rotation, so it doesn't actually look like a hole on the wall. Any help??
var hit : RaycastHit;
if (Physics.Raycast (transform.position, fwd, hit, attributes.Range))
{
print ("We hit something!");
Instantiate(Hole, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
}
Answer by jonnyhopper · Oct 27, 2013 at 10:18 AM
It's hard to say without seeing the prefab (can you post a screenshot of the error?)
But, have you tried using transform.forward or transform.up instead of Vector3.forward in the Quaternion rotation?
The hole is just a Unity pre-build plane with a texture on it.
Here's a screenshot with the problem:
Right, I see. Try using Quaternion.LookRotation( hit.normal) or after it's instantiated, just set transform.up = hit.normal on the instantiated object.
Right, I see. Try using Quaternion.LookRotation( hit.normal) or after it's instantiated, just set transform.up = hit.normal on the instantiated object.
Thank you so much! It perfectly works! :)