- Home /
Instantiate an empty on a local raycast hit position
Hi everyone !
As described in the title I'm having trouble trying to instantiate an empty on a local (meaning transform.forward not Vector3.forward) raycast hit position.
That worked when I was trying to instantiate it on the global axis but since I changed Vector3.forward to transform.forward, I don't know how to modify my instantiate parameters to match with it.
Here is a sample of my code :
function Update () {
var hit : RaycastHit;
dashDist = hit.distance;
Physics.Raycast (transform.position, transform.forward, hit);
}
function ShortDash () {
var hit : RaycastHit;
Instantiate (dashEmpty, hit.point, Quaternion.identity);
}
Does anyone know how can I fix this ? Any help will be really appreciated
You are defining var hit : Raycasthit in both Update and ShortDash, you don't want that if you are trying to use the hit from Update in the hit.point in ShortDash; also you don't have transform.forward + (some offset) - don't you need that?
Thank you ! You were right, I managed to make it work properly.