In my last post I spoke about needing to test the rifle to see how accurate it was. After creating some targets to shoot I was finding out that I was apparently missing the targets quite often. I added a line render to the bullet to track where the bullet goes and I found that the bullet would actually pass through the target, despite my script stating that both the bullet and target should destroy once they collide.

What went wrong?

After looking through my code and trying different bullet speeds, collision colliders and other methods I was still having this problem. I decided to search this problem online when I came across other people having the same problem (example one and example two). I then came to the conclusion that the system was unable to handle the speed of the bullet colliding with the target and so a better solution would be to use raycasting instead.

Changing how the gun shoots

First thing I did was turn any existing lines of code for shooting into comments. I wanted to keep the commented lines of code in case I couldn’t work out how to make the raycast shots. Then, with help from this guide by Unity, I was able to work out how to raycast the shot of the gun without any errors or conflicted code.

What has changed?

After retesting the rifle I am now 100% accurate when shooting the targets. I then changed the target scripts from destroying the object to changing colour from red to green to help show whereabouts I hit the box for debugging (as shown below)

Fig 1: Red boxes are the ‘targets’ which you shoot will change to green.

I also added a blue line render for debugging the accuracy of the shot (as shown below)

Fig 2: The blue line to indicate where the rifle is pointed at and what it has shot.

What next?

Now that I know the rifle is accurate at shooting, I will start creating a mock scene to test out the rifle at different ranges. Once I have planned out what ranges to test the rifle from I can begin to create a test game which others can play test.

References (2017). [SOLVED]: bullet passing through object in specific condition – Unity Answers. [online] Available at: [Accessed 6 Feb. 2017]. (2017). Solid walls not always stopping bullets | Unity Community. [online] Available at: [Accessed 6 Feb. 2017].

Unity, (2017). Let’s Try Game Dev: Shooting via Raycasting – Unity Official Tutorials. [online] YouTube. Available at: [Accessed 6 Feb. 2017].