To control the gun, I used what I had learned from the menu toy and used a Line Trace from the camera centre out to find what was hit. I didn't use the gun as the origin of the line trace as this would be too unpredictable with the character animations moving the model around.
Here is a shot of the code for the aiming and firing.

It looks complicated, but the basic jist is we are firing out a line trace from the camera, detecting what has been hit, then using the Apply Point Damage transfer we set up for the melee character, using the line trace hit object as the target.
I have a variable that tracks ammo, which I have set up to be 10 shots before re-load. The re-load animation plays if the player presses fire with zero bullets, and this refreshes the total. This variable is linked to the ammo counter in my shooter UI which I will show further down.
I created a UI Widget with an aiming reticule in the centre, which is displayed whenever the player enters aim mode. I already moved the player camera off to the right of the character model in the viewport. When the player enters Aim mode, a Field of View zoom takes place to make the player feel more accurate.

You can also see the Ammo counter in this screen shot which reduces with each shot, then replenishes when you re-load.
Extra Gameplay Mechanics
I added a couple of extra gameplay mechanics to the shooting for some variety.There is a bullet time which uses a timed Time Dilation node to slow the action down for a short period
I also added an AOE blast attack to save you from getting cornered by a large group or enemies. The core of this is a Radial Impulse on the character which is activated by a button press.
This sends the enemies flying away, plus I added an explosion particle effect to this ability.
No comments:
Post a Comment