r/unity_tutorials • • Nov 01 '22

Video Learn how to implement procedural recoil based on a range, or even a texture for more "predictable randomness" on your bullet spread! Gun Series Part 2 Full Tutorial in Comments!

79 Upvotes

10 comments sorted by

3

u/LlamAcademyOfficial Nov 01 '22

Full Tutorial on YouTube

Hey all! Happy #TutorialTuesday!

This week is part 2 of the gun series, where you'll learn how to make, from scratch, a highly-customizable scriptable-object-based gun system that supports all kinds of things, like what we're doing today - procedural recoil!

If you're going to have more than a couple of guns in your game, you'll likely find a prefab-based workflow becomes cumbersome to keep cleanly structured and in sync as you extend functionality, add VFX, and want to reuse configurations.

In this video I'll be covering 3 modes of recoil/bullet spread

  1. "None" - you're always perfectly accurate

  2. "Simple" - choose a random value between some limits, getting closer to those limits the longer you "spray"

  3. "Texture-Based" - choose an offset based on weighted random selection of pixels to give a more "predictable" spray, sampling larger areas the longer you "spray".

This is only part 2 in what's going to turn out to be a relatively long series. I'm going to cover other topics like:

  1. Reloading

  2. Fire Modes (burst/automatic/single shot)

  3. Sounds

  4. Projectile-based guns

  5. Damaging enemies

  6. Modifiers

  7. Attachments

  8. Skins

  9. And more 🙂!

As always, the full project for this video is available on GitHub!

4

u/Aangoan Nov 01 '22

Thank you for this!

1

u/LlamAcademyOfficial Nov 01 '22

You’re very welcome 🙌

2

u/[deleted] Nov 01 '22

As someone who has never made a game and wants to make a shooter, all that code is intimidating lol

2

u/LlamAcademyOfficial Nov 01 '22

😅 don’t be scared! This is part 2! We did a lot of that in part 1. There is a non-trivial amount of code here, but for a highly configurable system with a lot of guns, it takes some code!

1

u/[deleted] Nov 01 '22

Thanks for the reply! I have to learn some basics but I was hoping that it would make sense and be less scary once I got started.

2

u/LlamAcademyOfficial Nov 01 '22

You can do it! Start small, understand the basics of how scripts work in Unity and build up from there. Making a shooter can be pretty complicated, so probably not the best starter project. Once you understand the basics I think you can check out this series and understand what’s going on.

If you have questions, don’t be afraid to ask!

Edit: You also don’t have to use texture-based randomness, that was just something fun I added for more granular control.

1

u/[deleted] Nov 02 '22

Why does it look like an ad you would see on YouTube shorts

2

u/LlamAcademyOfficial Nov 02 '22

Well…. This trailer is actually a square-cropped version of the YouTube Shorts version of the video 🙂