I began by creating a new UE5 project using the FPS template. This gives you a character controlled in first person who moves with WASD, jumps with space and can walk over a gun to pick it up. Once picked up, the gun can be fired with left click, launching a bouncing projectile that applies force.
To pull off the impressive acrobatic tricks I want in this game, the player needs to be much more mobile than this default one. The first step in this direction was to increase the movement speed up to 1000, the jump velocity to 800 and the air control to 0.5. This allows the player to traverse much more quickly and accurately. I will later be adding advanced movement options like air-jumps, dashes, slides and wall-runs but this will do for now.
Next I changed the base weapon to turn it into our default gun, a bolt-action sniper reminiscent of the legendary Intervention from CoD MW2. I made the previously spherical projectile smaller and thinner to resemble a bullet until a replacement model can be found. I also removed its force applying abilities and greatly increased its velocity up to 10000. I'm considering changing this to a hitscan at some point but for now a very fast projectile will be fine.
The weapon system in the template works by adding a weapon component actor to the player character when they walk over the weapon pick up. So I modified this weapon component actor to become our sniper rifle. I began this by adding a delay between shots, as by default the gun has an infinite fire rate. This was done by creating a "in time between shots" bool which if set to true, prevents an firing input.
Using the default firing blueprint, left clicking spawns a projectile, plays a sound and performs a recoil animation. I added code at the end of this to set "in time between shots" to true, delay for "time between shots" seconds (currently 0.5) and then set it false again, allowing the player to shoot.
I then added an ammo system. A current and max ammo int were added, both set to 5. Firing checks ammo is more than 0 before working, then decrements the ammo value.
A reload input action was added to the project and bound to R. Pressing this sets a reloading bool true if it isn't already and if ammo isn't full it begins a timer which lasts 1 second currently. After this time, reloading is et false and the ammo is filled.
But now we need out bullets to do something. I added a current and max health float to the player, added an interface with a "take damage" function and modified the projectile code to call this function when colliding with the player. When the player receives this message it takes the damage from its health and prints "dead" at 0 health.
All weapons will have a secondary function so I added a "secondary" input action. For the sniper this function is to aim down the scope, zooming your vision to allow for longshots and quick-scopes. So players can quick-scope properly with a single click rather than having to toggle aiming on and off with two clicks, I added both a secondary button down input and a release input, both bound to the right mouse button. This action just halves the field of view while held down.
To communicate this all to the player I added a new UI widget which is applied to their viewport on being play.
To this UI I added a tiny square image to the centre, a text element to the bottom right to display ammo/max ammo, text above that saying reloading when doing so, a progress bar at the bottom centre of the screen with fill equal to health/max health and text on that showing the same. Here is a video of everything in action:
Next I aim to get some new assets and animations in to make the weapon look better and give the enemy an AI so that it can fight with the player.
Comentários