Introduction:
The first step in making the weapon shoot is done. Now shooting has an animation and linecasting enabled so it the bullets have a point of origin, trajectory and point of impact.
Firing Weapon/Animation:
Very simple animation was added to the player when firing the weapon. Basically it looks like a bit of recoil from firing the weapon at the hip.
I also added in a simple sound effect for the firing of the weapon that was part of the default assets of the third person unreal engine project.
Linecasting (Line Trace):
Finally a small amount of math. I took the origin world location of the end of the weapon (FirePoint static mesh) for the start of the linecast. I also took it’s forward vector. I multiplied the forward vector by 2000 (the range it can fire saved in a variable) and added it to the world location which results in the end of hte linecast. Now it draws a virtual line 2000 units straight from where it was pointed every time the player left-clicks while aiming down the sights (ADS). I have debug mode turned on for the linecasting so you can see the path of the bullet.
At the moment it fires the bullet from the end of the weapon. Depending on how this feels in the game I may switch it back to firing from the center of the players perspective (camera). Personally I prefer the more realistic approach to have it fire from the location of the end of the weapon.
Conclusion:
This was just a small step in the project, but it marked the end of one of the sections of the tutorial. Next up will be adding in health and destruction.