Game Development Reference
In-Depth Information
How it works...
We create a function called FlashDmgTimer() , which is really just a series of if
statements that check to see if our pawn's health is below a certain threshold, and
if so, calls FlashDmg() at a set interval. The lower the pawn's health is, the more
often the pawn flashes red.
FlashDmg() is really just calling another function inside it, SetBodyMatColor() .
We pass in our DamageBodyMatColor and DamageOverlayTime parameters to
determine the new body material color (red) and how quickly it flashes over that pawn.
Finally, the FlashDmgTimer() function is called each time the pawn is hit.
Creating a crosshair that uses our weapon's
trace
We've previously covered crosshairs and aiming in other recipes, but we're going to handle it
in a different manner now. Rather than always have our pawn fire at the direct center of the
screen, we'll change some behaviors so that our projectiles fire using the gun's rotation. Both
look and feel more accurate and realistic.
We'll do this by drawing a trace from the barrel (socket) of our weapon, and using the
weapon's rotator to draw the crosshair at the end of the trace.
Getting ready
Start by having your IDE open and ready to make some changes. We won't have to create any
new classes, but we will alter the behavior of our existing ones by adding some functions.
How to do it...
1. The first thing we need to do is override the GetBaseAimRotation() function in
our TutorialPawn class:
/*****************************************************************
* Returns base Aim Rotation without any adjustment.
* We simply use our rotation. Only use this if you want
* your weapon trace to follow where your gun is pointed.
* Comment out if you want to fire in middle of screen.
* @return POVRot
*****************************************************************/
simulated singular event Rotator GetBaseAimRotation()
{
 
Search Nedrilad ::




Custom Search