Weapon framework and how to work with them

This isn’t a tutorial about making an FPS game.


Better title: I talk about how guns (animations) usually work and if you have a problem with them then read this yes.

There are many great FPS games out there that have incredible mechanics. And I am here to use my imagination and tell you how these animations and effects were created.

Am no master in guns so if you have something to add then go on.

Animation events

Ooooh, this is an important part of animations. These events fire whenever a marker placed by you is reached, and different effects can happen at that time. For example, if you have more than 1 sound at the reloading animation, just like Arsenal has, then you can add these with custom names and play the sound when the magic GetMarkerReachedSignal event has fired. It is recommended for these types of things and I strongly suggest you use them.


Automatic guns

Ah. The most simplest and used guns in the world of FPS. There isn’t much you need to know here, just the basics:

  • Reloading sound(s) and animation
  • Shooting sound(s) and animation
  • And, well uhh, scripting knowledge.

With all of these in mind, you are ready to go and script that awesome :gun:.

Advanced

If you’re ready to script a more advanced gun, for example, if you reload and then equip another weapon, the (in-reloading) weapon’s state remains the same, like an in pause reload.
You would do more than 1 animation, the number of animations is up to you, but the more the better.
With the usage of Int or Number OR String variables, you can store the current state of the gun.
Another (pretty much unrealistic) way to do is having 1 reload animation, Pause it and all of the sounds playing on unequipping, remembering the state of the gun on equipping, and on equipping the gun you play the animation and sounds.

Pistols

There’s so secret here, same as the Automatic guns, but, y’know, not auto.

Shotguns

Oh no. The most High-Tech Code Big Hard Amazing So_Hard gun to make. Prepare for a biggie lesson.
What you need:

  • Sounds (shooting, putting shell into shotgun, pumping it, etc.)
  • Animations{
    You will need an animation (or more, randomize them) for the shooting event, an animation for the pump event, and more importantly, 3 more animations:
  1. Placing the hand behind the camera to get shell;
  2. Putting shell into the shotgun (not looped, you are gonna need this animation for usage more times);
  3. Placing hand back on the pump and getting ready to shoot.

And the framework would be like this:

  1. Shoot the gun (shoot anim)
  2. Pump the gun (pump anim but only if you have remaining ammo)
  3. Placing the hand behind camera anim
  4. Playing the shell anim more times, depends on how much you shoot
  5. Placing hand back on the lever.
    }

On the scripting part, you can store an IntValue and increase it every time the player shoots, and on the reloading part, you can repeat or for loop it as many times the value is, then reset it to 0, once the ammo is full.

Rocket Launchers

This one, well I am not sure, but uses:

  1. BodyVelocity with BodyGyro
  2. BodyPosition
  3. AlignPosition
  4. TweenService
  5. CFrame (Understanding CFrames)

And on the animation part, same as the shotgun.
I suppose applying damage works by the Touched event or Tween.Completed and check if players are in radius.

Grenade Launchers

This depends on how you’re making it. For example, if you’re doing the way Roblox did it and just gonna reload the entire stock with one animation then that’s simple, just like the Pistol mechanic. However, if you want to do it the following way:

It’s satisfying, isn’t it?

Then just use the Shotgun mechanic. Simple, right? Well, no.

Snipers

The gun mechanic works pretty much as pistols, but with more damage being dealt, and a different scripted aim scope point thing. The classic way is to increase the FOV and moving the camera forward or use this amazing resource by BoatBomber.
First way:

  1. (Ammo): Usage of the mechanic just like pistols, actually basically the same system
  2. (Bullet reload): 2 Animations. Easy, right? Well, just the shoot and reload animation. Reload happens only if there is ammo left and fires after shooting. And that just sounds weird.

I guess that’s it then. Thanks for reading all of this (done in 3 hours, what can I say), and if you have any questions feel free to DM me! I would consider more weapon types or mechanics too!

6 Likes