• Register
Post news RSS Fursan al-Aqsa Dev Blog #9 - Making-Off Weapons and Projectile Physics

In this article I discuss the technical details of how I created the weapons of my game, and how I did the physics simulations for the projectiles using Unreal Script.

Posted by on

Whenever you think First Person Shooter, or Third Person Shooter games, what is the first thing that comes to your mind? Badass Killer Weapons, right?

For a long time, shooter games tried to simulate real world warfare, but some games may multiply the reality by some craziness, which makes the gameplay experience fun, even though it is not very realistic.

In the end, I think that the most important thing for a weapon on a shooter game is to make the player feels a Bad Ass Super Hero killing all the bad guys :)

Thinking on this, I began to create the weapons for my game. But as my game is about the real war between Palestine x Israel, I tried to make these guns as most realistic as I could, and I opted to recreate real guns used by Israel Army and Palestine Resistance.

As everybody knows, and people keep asking me. No, I did not model the weapons myself, I did purchase model packs, but did make some slight changes on these weapons models, adding some details here, and there, changing textures, and so on. If I would model all the assets I am using on my game, being a solo dev, it would take for me 100 years to finish developing this game :D :D :D

I plan to have thousands of weapons in my game, however, as I will be releasing (and developing) this game into chunks (episodes), each episode will come with different weapons, character skins, maps and game modes.

For this Episode 0, which will be releasing in March 2020, these are the weapons which will be available:

Which are (in order): Combat Knife, Desert Eagle with Silencer, Makarov Pistol, AK-47 Rifle, M4A1 Rifle and RPG7 Bazooka.

Also being an old gamer (36yr), and a poor gamer :D :D :D which don't have money to purchase new games, neither purchase a PC capable of running these new games, I need to stick playing my old and retro N64 games for taking inspirations.

Being a Nintendo 64 Fanboy, I still play and love Goldeneye007 and Perfect Dark, which in my opinion, they are simply the best shooters of all times.

So I did play these on my old Project64 Emulator to try to dissect what makes the gunplay on these games so pleasant and fun.

After a while, I realized that what makes the gunplay so fun on these games are 3 points:

1- The feeling of power the gun has while shooting;
2- The reloading animations;
3- The hit reaction animations it triggers on the enemy characters;

Taking these 3 points into observation, I began to program (in Visual Studio 2008 with Nfringe plugin for Unreal Script) my weapons. I am proud because the programming I did all by myself.

The default UTWeapon class, the base code for weapons which comes outside the box with Unreal Engine 3 / UDK, is just a very basic system, which does not contain any reload system, just a basic bullet (ammo) count.

So the first step was to create a good reload system (a simple one) for each weapon, because each weapon has it's own reload animation time and other specific properties.

Here is just a small part of the reload code (it's big):

class WeaponReloadM4 extends UTWeapon;

//these variables are for handle the ammo quantity in the magazine
var int MaxMagAmmo, TransferAmmo;
var bool bIsReloading;

//these are the custom class functions that will overwrite the original functions/////////
//function consumeAmmo//////////////////////////////////////////
function ConsumeAmmo( byte FireModeNum )
	// Subtract the Ammo
	//reload system mod
//function consumeAmmo//////////////////////////////////////////

//original add ammo function/////////////////////////////
function int AddAmmoDefault( int Amount )
    //default add ammo count
	AmmoCount = Clamp(AmmoCount + Amount,0,MaxAmmoCount);
	// check for infinite ammo
	if (AmmoCount <= 0 && (UTInventoryManager(InvManager) == None || UTInventoryManager(InvManager).bInfiniteAmmo))
		AmmoCount = MaxAmmoCount;

	return AmmoCount;
//original add ammo function/////////////////////////////

//add ammototal function for reloading system////////////////////
function int AddAmmo( int Amount )
    //custom reload add ammo count
	AmmoTotal = Clamp(AmmoTotal + Amount,0,MaxAmmoTotalCount);
	// check for infinite ammo
	if (AmmoTotal <= 0 && (UTInventoryManager(InvManager) == None || UTInventoryManager(InvManager).bInfiniteAmmo))
		AmmoTotal = MaxAmmoTotalCount;
	//custom reload variable
	return AmmoTotal;
//add ammototal function for reloading system////////////////////

//reload function to play reload animation///////////////////////
exec function Reload() {
  //this statement will prevent weapon reloading when ammo is full
  if (AmmoTotal > 0 && !bIsReloading && AmmoCount < MaxAmmoCount) {
    bIsReloading = true;
        //this will play the custom reload animation only on the half top body
		                                          //AnimName, Rate, BlendInTime, BlendOutTime     
        UTPawn(Owner).TopHalfAnimSlot.PlayCustomAnim('reload_rifle_M4_UT3', 1.0, 0.5, 0.35);
		//this will call the function to play reload animation on the UTAttachment Mesh

		//this will set a timer to unload magazine in rifle
		setTimer(0.15, false, 'UnLoadMagazine'); 
		//this will set a timer to load magazine in rifle
		setTimer(0.85, false, 'LoadMagazine');
    //this will play the allah_akbar sound
	PlaySound(SoundCue'dhikr.allah_akbar_1_Cue', false, true, true, vect(0,0,0), false); 	
	//this timer will be triggered after the duration of the reload animation which is 1.16 seconds
	setTimer(2.30, false, 'AddAmmoToMag');
//reload function to play reload animation///////////////////////

I can't give an Unreal Script Tutorial (maybe later on), however I like to people see this stuff I am creating, because Unreal Script is very intuitive, and whenever I program, I like to write on my code small observations and comments, so I myself can remember and understand why I have done so and so. Imagine seeing a code you created 5 years ago? If there are no comments, you may forget how the code works (at least my memory is not that good neither strong :D :D :D)

So after the reload class, I needed to create another class for each weapon, however, on Unreal Engine 3, a weapon is composed of many classes, like the Weapon Class itself, the Projectile Class, the Damage Class and the Third Person Attachment Class.

There are basically two kind of weapons on Unreal Engine 3 (UDK Engine): Instant Hit Weapon and Projectile Weapon.

The marjority of games done in UDK, which use guns, they use the Instant Hit Weapon. However, I thought to my self: Why not make all my game's weapons projectile weapons? This way they will look more realistic.

I just needed to create a simple particle effect to represent the bullet trace (and to be used as the projectile which is shot from the weapon). I think there is a specific code on Unreal Engine 3 for bullet traces, however, I prefeer to MISS (Make It Simply Stupid) :D

By searching on default UDK Particle effects, I found the rocket launcher projectile. I duplicated it (to keep the original intact), then began to mess with the particle effect, removing some emitter here, and there, untill I stayed with the base light trace. Then I just changed the colours to a reddish yellow, and voila! Here I got my weapon trace effect:

Now I just had to play with the weapons properties, like these ones:

//The maximum amount of ammo the magazine clip can hold

//The current ammo count

//The initial ammo count for this weapon if picked up from a weapon locker

//The maximum amount of ammo this weapon can hold

//We need to set an initial value for the reload function work and it must be the double of max ammo (it is extra ammo)

CustomWeapName="RIFLE M4A1"

	//visual properties///////////////////////////////
	//x -> distance from camera
	//y -> horizontal position
	//z -> vertical position

    Begin Object class=AnimNodeSequence Name=MeshSequenceA
    End Object

    Begin Object Name=FirstPersonMesh
    End Object

    Begin Object Name=PickupMesh
    End Object
	//this controls the projectile spawn position
	//x -> distance from camera
	//y -> horizontal position (negative value moves to left)
	//z -> vertical position	
	//visual properties///////////////////////////////
	//weapons in udk ultimate are ballistic, i.e, they trully shoot real bullets, projectiles which are controlled by physics properties
	//here the properties of the bullet are controlled by the class UTProj_Enforcer

    //muzzleflash for 1st person model

	//ammo fire speed functions///////////////////////////////
	//ammo fire speed functions///////////////////////////////
	//weapon icon for Canvas HUD Multiplayer

    //CrosshairImage for rifles

//custom zoom properties to simulate iron sights effect	

//custom zoom properties to simulate iron sights effect	

Then also I had to play with the projectile properties and values:

class UTProj_M4 extends UTProjectile;

simulated function PostBeginPlay()
    // force ambient sound if not vehicle game mode
    bImportantAmbientSound = !WorldInfo.bDropDetail;

    //this is the visual representation of the bullet, which is a particle system based on the rocket launcher
	//I just changed the mesh by a bullet mesh (case) and the trail effect to simulate a bullet tracer



I will never be able to create a realistic ballistic physical simulation for my game, as it is hautingly hard for just one person (I consider myself a noob in programming yet). I just tweaked these values based on real life guns properties, not exact values, just an aproximation and comparison between guns (I have been reading some cool guns reviews on the web).

In example, in real life, the M4A1 Rifle's Projectile has bigger acceleration and causes more damage than the AK-47. So I did this on the projectiles properties, I made the speed and damage of the M4A1 projectile bigger than AK-47's.

The same for Makarov Pistol and Silencer Desert Eagle (which is the most devastating pistol available).

At the very least these properties are based on real guns properties and not random values from my mind.

Other detail to make my gun feel bad ass is the fire sound. The original sound which came with the weapons I purchased was not realistic. Because of that I decided to use real gun sounds from Youtube Videos, especially those who instruct how guns work. I edited the gun sounds in Adobe Audition, removed some noises here and there, until I got the final fire sound for the weapons.

Also other sounds, small sounds which make a big difference are the bullet impact sound and the projectile travel sound (that whoosh effect the projectile makes while transversing the air).

As for the Hit Reaction animations, I already showed on previous videos, however, I am creating many more hit reactions to give my game some kinda variation (avoid being repetitive).

I hope that you all enjoyed reading this new devblog, and untill next update.


Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.