Hit reactions and dying

So far you can shoot our countess as much as you want and nothing interesting happens. We'll fix this with a few code changes to our projectile, and some significant logic we can bundle up in the melee controller. Quickly going through this, we'll add a health parameter to the melee controller like so:

UPROPERTY(EditAnywhere, BlueprintReadWrite, SaveGame, Category = "Health")
float Health = 100.0f;

Then modify the projectile's on hit to look like so:

void AMasteringProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
        // Only add impulse and destroy projectile if we hit a physics
        if ((OtherActor != NULL) && (OtherActor != ...

Get Mastering Game Development with Unreal Engine 4 - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.