- Home /
Raycast hit.point is returning wrong
First sorry for my english, I'm searching this bug for 2 days.
I have a video about this problem. I'll attach Video
I just want to make bullet holes. When I fired creates a bullet hole but in different position.
I tried everything.. i can't resolve this problem.
RaycastHit hit;
//Vector3 fwd = Kamera.TransformDirection (Vector3.forward);
Ray ray = new Ray(Kamera.position,Kamera.forward);
if (Physics.Raycast(ray,out hit,10f)) {
Quaternion hitrotation= Quaternion.FromToRotation(Vector3.up, hit.normal);
Instantiate(iz,hit.point,hitrotation);
Debug.Log (hit.point);
Debug.Log(Kamera.position);
Debug.Log(hit.collider.name);
}
Please make sure your iz gameobject doesn't change position when rotating.
Well, make sure the child of the prefab is also (0,0,0), and please check whether you are using any negative value for the cube size or it's box collider. It looks strange!
Answer by team_eden · Feb 01, 2015 at 02:10 AM
Your raycast may be hitting a collider attached to the player, be sure that it is ignoring all the player and gun layers!
That is my 2 cents, good luck!
Answer by Tumay · Feb 01, 2015 at 04:47 AM
Resolved !
Problem is the child of the prefab :)
Would you mark my answer correct then, by the sounds of it, I was right. Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182050im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycasting how to find position on end of ray float distance 1 Answer
How do I create bullet hole for my gun? 0 Answers
Need to find a point along a linecast slightly closer to the origin than hit.point 1 Answer
Get a point on raycast when collision = false 1 Answer
issue with bullet hole decal 1 Answer