Dev Log 11# Creating a projectile weapon adding projectiles and bullet shells
- camjhill737
- Oct 4, 2023
- 2 min read
As a gaming fanatic I'm aware of many shooter games whatever form they may take and some will implement projectile based weapons others will implement hit scan weapons some will implement both. Projectile weapons offer bullet drop off which you'll commonly see in games like battlefield and hit scan weapons which you'll see in more arcade like shooters.
I wanted my assault rifle to have bullet drop off so I learnt how to create a projectile weapon. First I created a new weapon class called projectile weapon which will override the shoot function by passing in a FVector by reference because the variable that will be passed in is the HitTarget which is the final destination for the bullet. The projectile weapon also spawns a projectile actor class which was created alongside the projectile weapon class.
The projectile class consists of UBoxComponent to handle collision, a projectile movement component to help handle the physics of the moving projectile, the UParticleSystem to handle the visuals of the projectile.
I set the bReplicates to true for this class because seeing all the bullets travel will add a fun chaos to the game and after implementing this I learnt something cool about destroying actor classes. By implementing the Destroyed function into your actor class wherever and whenever the actor is destroyed in game the destroyed function will be called under Unreal Engine's hood and the engine will broadcast this information to all clients because the broadcast function in unreal is tied to a multicast delegate. As is the case with multicasts in unreal make sure that the actor is destroyed on the server first because multicasts only invoke to all clients from the server.
I also created a bullet shell class which is just for more visual effects its spawned and ejected from the socket on the assault rifle which also has it's own sound effects which helped me discover and learn about sound cues and sound attenuations the video you'll see below which has been taken from the not so distant future these shells are replicated because they're spawned in the shoot function but by setting the lifespan to 3secs they are also destroyed on all clients and its a common visual effect that you see in most if not all shooter games. P.S they're the little pink things by the character's feet
Comments