Upcoming Events! Community Event Calendar
Social Media Follow us, or not!

Bugsmashers: Shotgun Recoil Written Wednesday 24th of May 2017 at 12:00pm by StormyWinters

As per usual, anything said during the show is subject to change by CIG and may not always be accurate at the time of posting. Also any mistakes you see that I may have missed, please let me know so I can correct them. Enjoy the show!

TL;DR (Too Long; Didn't Read)

  • Bug is where the gun performs the recoil action before the projectiles are even emitted from the weapon

  • In this case it’s a simple fix of moving a small bit of code from one place to another so that it then performs all actions in the correct order: Projectiles get emitted then recoil phase occurs   

Full Transcript

Mark Abent: Hey everyone, welcome to Bugsmashers. I’m your host Mark Abent, I’m a Senior Gameplay Programmer here to show you all the awesome bugs that make me cry. 

Hey everyone, we are here in my fun test level of shenanigans, we have a bug today with the shotgun. So let’s hop in the game and take a look, so put a shotgun on the ground and going to grab it. Grab my shotgun and the bug is should I say when you fire a gun, you expect the projectiles to go approximately where you’re aiming, then you do a recoil. So, let’s see what happened, pew… as you can see not exactly what we expect. 

You know you have the shots lining up towards the centre which is where the shells should go but we’re also getting some on the very top, and our spread is obviously not that bad. What’s actually happening here is when we shoot, it’s actually emitting the projectiles during the recoil stage, rather than emitting them all before we recoil. You expect to when you shoot, you fire, projectile leaves, then you recoil. Not I shoot, recoil then the projectiles leave. 

So we have a slight order issue. Let’s step into the code, here is our fun legacy shotgun fire mode. This is all going to get cleaned up in the new weapons system but for now we have this awesome legacy code and we actually have multiple phases of our firing. We have a set up phase, which is when I have my gun we try to figure out where the barrel of the gun is going to be, so that we can emit the projectile there. Then we have a recoil phase where after we have emitted, we need to now create the muzzle effect and any interesting trails so we can have a separation. 

Unfortunately, this little fun boole here is the thing that controls when we actually fired. So, when we come into this fun little bit of code, we basically shoot, we don’t create a projectile yet because this boole is true we now emit the recoil before we even got to the recoil phase. So what we want to do is we move this so when we shoot, we have yet to create the projectiles because they’re deferred response, they may not happen right then and there. We need to make sure we do the fired phase during the recoil and it should just be as simple as in the recoil phase, then we mark it as true. 

So what this should now do, I’m going to hit recode, is I fire the gun, it’s going to prep spawning some, let’s see where’s that at. so this guy, so we fire, we prep some projectiles that we’re going to spawn, they get spawned in the deferred spawning process and when it happens we get this call back and we should be in the setup phase where we’re going to emit the projectiles. Then once they’ve all emitted, we go to the recoil phase which is now going to spawn the muzzle effect and pretty particles. Then we signify during that recoil phase, we want to do popping of the gun. 

Let’s see what happens now, aha as you expect. Now all the projectiles get emitted than the recoil phase occurs and you get the actual shotgun working as intended not nerfed because my projectiles are blowing all over the place. Hope you guys enjoyed, until next time. 

So, we one of those infamous bugs where having a variable in one spot versus another spot just brings completely different behaviour. When you have your shotgun and you shoot it, you expect the gun to shoot the projectile where you’re aiming, then recoil up. Not shoot the gun, recoil and then emit the projectile. So just moving that simple boole into a completely spot so it makes sure that we marked it as fired after recoil resolved the issue and now we shoot where we expect, then recoil. Hope you guys enjoyed, until next time.

StormyWinters

Director of Fiction

Moonlighting as a writer in her spare time StormyWinters combines her passion for the written word and love of science fiction resulting in innumerable works of fiction. As the Director of Fiction, she works with a fantastic team of writers to bring you amazing stories that transport you to new places week after week.