1

I have a problem with my Raycast/BulletHole in my FireRaycast() Function.

If I shoot, it doesnt spawn my Hitsparks and BulletHoles on the hitted Raycast Position (Position where the bullet impacts). If they spawn, they spawn in the space in front of my weapon. (see pic) In this case, the console debug log tells me that I hit the FPSController...?!?

Do anybody have a solution for that?

I want that it always hits walls or the bottom and so on..

function FireRaycast() {

var hit : RaycastHit;



if (Physics.Raycast(shootPoint.position, shootPoint.transform.forward, hit, range)) {

   Debug.Log(hit.transform.name + " FOUND!");

   var hitParticleEffect = Instantiate(hitParticles, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));


   var bulletHole : GameObject= Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));

  Destroy(hitParticleEffect, 1f);
  Destroy(bulletHole, 2f);

}
}

Heres an ingame screenshot: enter image description here

Thank u guys!

Programmer
  • 121,791
  • 22
  • 236
  • 328
1zz0
  • 264
  • 3
  • 18
  • Please add your code not picture of it. – Programmer Sep 04 '17 at 20:01
  • *"the console debug log tells me that I hit the FPSController...?!?"* The log tells you are hitting "Hanger" from your screenshot. – Programmer Sep 04 '17 at 20:17
  • yes, the raycast works - i shot around the environment. If u watch on the bottom left corner, there is the latest log with "FPS Controller FOUND!". – 1zz0 Sep 04 '17 at 20:24
  • I also used a EmptyGameObject with the name "shootPoint" to simulate the bullet. The plan was, that it spawns my hitsparkles and bulletholes on that impact position of where the raycast goes. It seems like, that the hitSparkle and the bulletHole Spawn are trapped in my FPSController.. – 1zz0 Sep 04 '17 at 20:27
  • I changed the title to reflect the issue then marked it as a duplicate. Reason for this is that I don't want to copy and paste what I said before. The duplicate should fix that error for you. Use layers to represent the target object and the "FPS Controller" then use bitmask to make sure to only hit the target when doing `Physics.Raycast`. Let me know if there is a problem. – Programmer Sep 04 '17 at 20:28

0 Answers0