Bouncing Bullets with Hitscan Guns




Published: 01 Feb 2022

Learn how to implement, from scratch, raycast (or "hitscan") bullets, with trails, that can bounce/ricochet off objects!


We'll start off by using some free starter assets from Unity and the New Input System. We'll write a Gun script from scratch that shoots raycast bullets that have a bullet trail / bullet tracer that shows where the bullet is going. Specifically, we're not implementing bullet spread in this video to keep our gun shots accurate to showcase the ricochet behavior. Finally we'll add in the bouncing bullet behavior and get into the demo.


This video has some similarities to what I refer to as "the previous video" where we first implemented Raycast Shooting and Bullet Tracers: https://youtu.be/cI3E7_f74MA. This time we're fixing some of the issues that were pointed out in the comments and adding new features!


There are 3 key lessons to learn in this tutorial:

⚫ How to implement Raycast bullets that move at a constant speed (improvement over: https://youtu.be/cI3E7_f74MA)

⚫ What is Vector3.Reflect and how does it work

⚫ How to implement recursive Coroutines


🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂

👨‍💻 Get the FULL FREE PROJECT on GitHub: https://github.com/llamacademy/raycast-bouncing-bullets

🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


📚 Resources

🟠 Vector3.Reflect: https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html

🟠 Physics.Raycast: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

🟠 New Input System: https://docs.unity3d.com/Packages/[email protected]/manual/index.html

🟠 Object Pooling for Unity 2021+: https://youtu.be/zyzqA_CPz2E


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.