Introduction To UFPS: Unity FPS Tutorial

In this Unity FPS tutorial you’ll learn the basics of working with UFPS to build the basis for a solid first person shooter in Unity3D. By Anthony Uccello.

Leave a rating/review
Save for later
You are currently viewing page 2 of 4 of this article. Click here to view the first page.

Adding Bullet Holes

You can already hear the gun and watch shells eject! There’s even a cool flare effect at the front of the gun! UFPS does that for you, which is one of the features that makes it easy to add and configure new guns.

Try shooting something and tell me what’s missing. Is that gun shooting blanks? Why are there no bullet holes?

Anytime you shoot something, you should leave a mark. Stop play. In the Hierarchy view, click the dropdown arrow to the left of the Environment GameObject and select the child Wall GameObjects.

In the Inspector, click Add Component and type vp_SurfaceIdentifier into the search field. Click vp_SurfaceIdentifier — the only available script — to add it. Click the dot to the right of the Surface Type field. In the menu that pops up, click the Assets tab and select Metal.


Select the Ground GameObject in the Hierachy and repeat the above steps, but select Wood for the last step.

The targets need a wood surface identifier, so click the dropdown arrow next to the Target and BackTarget GameObjects in the Hierarchy to expand them, and then select their children and add the vp_SurfaceIdentifier script component. Also set the surface type to Wood.

Click Play and try shooting the target, the walls and the floor. Now you can see the results of your handiwork, partner. :]


How The UFPS Pistol Works

No one ever defeated a horde of evil monsters with a single a pistol, right? :] You’ll add a shotgun soon, and it’ll be easier if you understand how the pistol works.

Expand the SimplePlayer GameObject in the Hierachy, and then expand the FPSCamera GameObject. Select the 1Pistol GameObject.

The number 1 in front of a weapon name represents the number the player should press to equip that pistol during gameplay. When you add new weapons, you’ll just increment the number and UFPS will automatically handle weapon swapping.

The 1Pistol GameObject has several important components:

  • AudioSource makes the pistol go “bang” when it fires.
  • vp_FPWeapon identifies this GameObject as a weapon in the UFPS framework and controls aspects that relate to the weapon itself.
  • vp_FPWeaponShooter handles effects like muzzle flash, shell ejection and the projectile.
  • vp_FPWeaponReloader handles sounds and animations that relate to reloading.

Note: Ammo and reloading are out of scope for this tutorial, but they’re something you’ll want to think about when you make your game. Also, there are many sections for these vp_FP components and the UFPS documentation covers them in full, so make it your first stop when you have questions.

Note: Ammo and reloading are out of scope for this tutorial, but they’re something you’ll want to think about when you make your game. Also, there are many sections for these vp_FP components and the UFPS documentation covers them in full, so make it your first stop when you have questions.


Expand the Position Springs section on the vp_FPWeapon Script component in the Inspector. This component sets up the gun’s on-screen position, which changes based on the state — for instance, when the pistol moves for zooming. Offset is where the gun sits on-screen.

Click Play and move the gun around by playing with the Offset values. By the way, you won’t mess up the game’s actual values while you’re in play mode.

Tinkering with settings in play mode is a good way to test and debug — but make sure you’re not in play mode when you’re actually trying to change settings. It’s easy to get wrapped up in things and forget you’re still in play mode, which can lead to extensive reworking and bad words coming from your mouth.


Look a little further down in the component to find Spring2 Stiffn and Spring2 Damp — these are the gun’s recoil settings. Spring2 Stiffn is ‘elastically’, or how the gun bounces back to its original position after firing. Spring2 Damp is how fast the bounce wears off. The easiest way to visualize this is by…actually visualizing it. :]

Click Play and move the sliders around for Spring2 Stiffn and Spring2 Damp to get a feel for what they do.


It can take some trial and error to make these animations look right, so don’t feel bad if your first few attempts make the gun bounce like a pogo stick.

Now that you’ve familiarized yourself with Position, it’s time to focus on Rotation. Expand the RotationSprings section on the vp_FPWeapon in the Inspector. Look at the Offset values, which are the same as what you saw in the PositionSprings section. The difference is that these values control the gun’s rotation.

Click Play and mess around with Offset values to get a feel for what it does.


Now think about how it looks when you fire that pistol. UFPS creates the animation on the fly by on interpolating between state values.

All you need to do is set up various state values in the vp_FPWeapon component — no need to import and set up animations for this effect. You’ll get hands-on experience with that when you add the sniper rifle and shotgun.

Stop the game play.

Dig a little deeper here. Expand the States section on the vp_FPWeapon in the Inspector and have a look at the pre-existing states and their associated data files. The data files track what values should change in the vp_FPWeapon when the state changes.

For example, take a look at the Zoom state. Double-click WeaponPistolZoom and have a look at the script file — it will open in your default code editor for Unity. It should be a simple data file with the following:

ComponentType vp_FPWeapon
ShakeSpeed 0.05
ShakeAmplitude 0.5 0 0
PositionOffset 0 -0.197 0.17
RotationOffset 0.4917541 0.015994 0
PositionSpringStiffness 0.055
PositionSpringDamping 0.45
RotationSpringStiffness 0.025
RotationSpringDamping 0.35
RenderingFieldOfView 20
RenderingZoomDamping 0.2
BobAmplitude 0.5 0.4 0.2 0.005
BobRate 0.8 -0.4 0.4 0.4
BobInputVelocityScale 15
PositionWalkSlide 0.2 0.5 0.2
LookDownActive false

These are the changes that must occur when the vp_FPWeapon enters the Zoom state. This might seem a little intimidating, but it’s actually quite easy — you can position the gun during play and then save a state file from there.