O'Reilly logo

Mastering Game Development with Unreal Engine 4 - Second Edition by Matt Edmonds

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 != ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required