In this post I would like to work on:
- Increasing spread when shooting,
- Decreasing spread when in idle,
- Dynamic crosshair that will tell me what’s the current spread,
<strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>.
Make sure you are working on the same version of the engine.
In earlier post we have created couple of variables in BP_MainWeapon. We need more:
- DeltaTime, (float)
- SpreadDecreaseSpeed (float, default: 0.1)
In Event graph create Tick event.
So basically we are decreasing spread all the time.
Now in BP_Weapon_Pistol set variables:
- SpreadMin = 0
- SpreadMax = 0.3
- SpreadCurrent = 0.3
- SpreadDecreaseSpeed = 0.25
And in Fire event add IncreaseSpread by 0.1 like here:
So every time we shoot we will increase spread by 0.1. At this point you will see that spread is working correctly.
Now we need to create an crosshair indicator to show us the spread.
Basically the best way to do this is in C++ using canvas (like in Shooter Example from Epic) I’ve tried to create this in HUD blueprint using Canvas as well but there is still couple of functions not exposed to blueprints (drawicon for example) so I decided to do this using UMG.
Create new User Widget and name it UI_Debug_HUD.
You would need to find crosshair assets. I’ve copied them from Shooter Example HUDMainTexture. UMG can’t draw image based on UV so each part of the crosshair need to be separated (center, left, right, top, bottom)
Here’s the designer settings for all of them:
Now in Event Graph create Tick event and let’s move crosshair elements depending on CurrentSpread.
Now in GameplayHUD in Begin Play create UI_Debug_HUD and add it to viewport. Remember that your Game Type should have GameplayHUD connected as HUD class!
Watch in HD it’s hard to see crosshair.
Implementing game is taking time but writing about this is taking much more effort!