Shooting around cover
The next step to this project was setting up shooting mechanics and shooting from a covered position, which I chalked down to a small task in my learning contract. However, this has turned out to be much more complex and time consuming than I previously thought, as there are quite a lot of variables.
Variables to consider
Should I peek over or around it?
Which direction am I facing?
which corner of the wall am I peeking from?
Where should I return to when I have finished peeking?
The first thing I did was create an event for aiming down sight. When the aiming down sight button is pressed, it checks if the player is in cover and if they are peeking at a corner. If they are not peeking it fires a line trace I created to determine the height of the cover. If the player is peeking, ADS (Aim Down Sight) peeking will be fired, if the cover is low and they are not peeking they will aim over the top.
Peeking
When ADS over low cover is fired, a Macro called "Leave cover" is triggered. This basically sets an "In cover" bool to false, which is checked whenever the player overlaps with cover. This affects character movement, which has to switched around, as the character is rotated to face the screen when in cover. Controller yaw input is also restored allowing the player to aim.
When ADS peeking is fired, a line trace records the last location the player was on the wall to return to later. It then fires a macro called "peek direction" to determine the direction the player is facing and creates an offset on the correct side for the player to move to.
Peek direction
This is the part that had me stumped for a while, I had my character peeking the wrong way in every direction so I had to set up a way to determine which side of the object was being faced. After relentless debugging I printed a string for the "Wall normal" hit by the line trace when the player takes cover. From this I discovered it would either be a + or - value on either the X or Y axis, From this I could compare the number and the axis to get my direction.
When the side of the object is determined, a bool for left and right (changed by character movement) checks which corner to peek from.