Blood Splat

Recently, whilst making an FPS game, I happen to implement a feature involving blood. The idea is, when you butcher zombies, their post-coagulated(?) blood spills on the floor they are standing or rather creeping on. Clearly we need to use something “other than” UParticleSystem for the purpose because we are not looking those particle effects which look like spray in air

The gif shows two kinds of blood effects. One is the blood-sprayed-in-air effect (particle effect) and other is splat on ground (decal).

For particle system we have the following Unreal C++ declaration

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Effects")
TArray<UParticleSystem*> BloodEffects;

and following code implementation

UParticleSystemComponent* PSC = NewObject<UParticleSystemComponent>(this, UParticleSystemComponent::StaticClass());
...			
PSC->SetWorldLocationAndRotation(LastTakeHitInfo.RelHitLocation + GetActorLocation(), LastTakeHitInfo.RelHitLocation.Rotation());
...

Here first we create new object of type UParticleSystemComponent and set to raycast’s hit location on the pawn. Hence spray effect can be seen.

What about the blot spats on the floor?

For that, we take help of decals.

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Effects")
TArray<FBloodDecalInfo> BloodDecals;

Basically, we send line trace from hit location (on the pawn) towards vertically downward direction and obtain the hit location on the floor

GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceStart + FVector(0.f, 0.f, -1.f) * 200, ECC_Visibility, FCollisionQueryParams(NAME_BloodDecal, false, this)))

and use Engine’s SpawnDecalAtLocation

UDecalComponent* DecalComp = UGameplayStatics::SpawnDecalAtLocation(GetWorld(), DecalInfo.Material, FVector(1.0f, DecalScale.X, DecalScale.Y), Hit.Location, (-Hit.Normal).Rotation(), 0);

to spawn blood decal at Hit.Location.

Participate in discussion