Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed spawn decal for moving characters #277

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
Binary file modified Content/Physicals/PM_Concrete.uasset
Binary file not shown.
Binary file modified Content/Physicals/PM_Metal.uasset
Binary file not shown.
Binary file modified Content/Physicals/PM_Wood.uasset
Binary file not shown.
16 changes: 16 additions & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ FString UCloud9DeveloperSettings::WeaponRecoilDecayCoefficientName = "r.WeaponRe
FString UCloud9DeveloperSettings::DrawShotDirectionAxisName = "r.DrawShotDirectionAxis";
FString UCloud9DeveloperSettings::WeaponDebugDamageInfoName = "r.WeaponDebugDamageInfo";
FString UCloud9DeveloperSettings::TaggingScaleName = "r.TaggingScale";
FString UCloud9DeveloperSettings::DecalLifeSpanName = "r.DecalLifeSpan";
FString UCloud9DeveloperSettings::DecalFadeScreenSizeName = "r.DecalFadeScreenSizeName";
FString UCloud9DeveloperSettings::VolumeName = "r.Volume";

// ReSharper disable once CppPossiblyUninitializedMember
Expand Down Expand Up @@ -75,6 +77,8 @@ UCloud9DeveloperSettings::UCloud9DeveloperSettings(const FObjectInitializer& Obj
WeaponDebugDamageInfo = 0;
DrawShotDirectionAxis = 0;
TaggingScale = 1.0f;
DecalLifeSpan = 20.0f;
DecalFadeScreenSize = 0.0f;
}

UCloud9DeveloperSettings* UCloud9DeveloperSettings::Get()
Expand Down Expand Up @@ -252,6 +256,18 @@ void UCloud9DeveloperSettings::InitializeCVars()
TEXT("Scalar for player tagging modifier when hit. Lower values for greater tagging")
);

RegisterConsoleVariable(
DecalLifeSpan,
*DecalLifeSpanName,
TEXT("Life span of the decals")
);

RegisterConsoleVariable(
DecalFadeScreenSize,
*DecalFadeScreenSizeName,
TEXT("Decal size to fade off screen")
);

log(Display, "%s", this | EUObject::Stringify{} | EFString::ToCStr{});
}
}
Expand Down
8 changes: 8 additions & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings
static FString DrawShotDirectionAxisName;
static FString WeaponDebugDamageInfoName;
static FString TaggingScaleName;
static FString DecalLifeSpanName;
static FString DecalFadeScreenSizeName;
static FString VolumeName;

// properties
Expand Down Expand Up @@ -144,6 +146,12 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings
UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug)
float TaggingScale;

UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug)
float DecalLifeSpan;

UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug)
float DecalFadeScreenSize;

UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug)
EUnUsedEnum UnUsedEnum;

Expand Down
18 changes: 2 additions & 16 deletions Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,14 @@ bool IsVertical(FVector Normal)
return FMath::IsNearlyEqual(Normal.Z, 1.0f, 0.1f);
}

FRotator GetNormalSurfaceRotation(FVector Normal, float Roll)
{
constexpr let DecalVPitch = 90.0f;
constexpr let DecalVRoll = -180.0f;
constexpr let DecalHYaw = 90.0f;
constexpr let DecalHRoll = -90.0;

let Corrective = IsVertical(Normal)
? FRotator{DecalVPitch, Roll, DecalVRoll}
: FRotator{Roll, DecalHYaw, DecalHRoll};

return Normal.Rotation() + Corrective;
}

UMaterialInterface* UCloud9PhysicalMaterial::GetRandomFirearmDecal() const { return GetRandomItem(FirearmDecals); }

FVector UCloud9PhysicalMaterial::GetFirearmDecalSize() const { return FirearmDecalSize; }

FRotator UCloud9PhysicalMaterial::GetFirearmDecalRotation(FVector Normal) const
{
let RandomRotation = FMath::RandRange(FirearmDecalRotationMin, FirearmDecalRotationMax);
return GetNormalSurfaceRotation(Normal, RandomRotation);
return Normal.Rotation() + FRotator{0.0f, 0.0f, RandomRotation};
}

USoundBase* UCloud9PhysicalMaterial::GetRandomFirearmHitSound() const { return GetRandomItem(FirearmHitSounds); }
Expand Down Expand Up @@ -76,7 +62,7 @@ FVector UCloud9PhysicalMaterial::GetBackgroundDecalLocation(FVector Location, FV
FRotator UCloud9PhysicalMaterial::GetBackgroundDecalRotation(FVector Normal) const
{
let RandomRotation = FMath::RandRange(FirearmBackgroundDecalRotationMin, FirearmBackgroundDecalRotationMax);
return GetNormalSurfaceRotation(Normal, RandomRotation);
return Normal.Rotation() + FRotator{0.0f, 0.0f, RandomRotation};
}


Expand Down
38 changes: 0 additions & 38 deletions Source/Cloud9/Tools/Extensions/UWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#pragma once

#include "Engine/DecalActor.h"
#include "Components/DecalComponent.h"
#include "GameFramework/GameModeBase.h"
#include "Kismet/GameplayStatics.h"

Expand Down Expand Up @@ -63,42 +61,6 @@ namespace EUWorld
OPERATOR_BODY(SpawnActor)
};

struct SpawnDecal
{
UMaterialInterface* Material;
FVector DecalSize;
FVector Location;
FRotator Rotator;
float LifeSpan = 20.0f;
float FadeScreenSize = 0.001f;
AActor* Owner = nullptr;
APawn* Instigator = nullptr;

FORCEINLINE ADecalActor* operator()(UWorld* Self) const
{
FActorSpawnParameters Parameters;
Parameters.Owner = Owner;
Parameters.Instigator = Instigator;

if (let Actor = Self->SpawnActor<ADecalActor>(ADecalActor::StaticClass(), Location, Rotator, Parameters))
{
if (let Decal = Actor->GetDecal(); IsValid(Decal))
{
Decal->SetDecalMaterial(Material);
Decal->SetLifeSpan(LifeSpan);
Decal->SetFadeScreenSize(FadeScreenSize);
Decal->DecalSize = DecalSize;
return Actor;
}
}

return nullptr;
}

OPERATOR_BODY(SpawnDecal)
};


template <typename BlockType>
struct AsyncAfter
{
Expand Down
41 changes: 25 additions & 16 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Engine/StaticMeshActor.h"
#include "NiagaraFunctionLibrary.h"
#include "Components/WidgetInteractionComponent.h"
#include "Components/DecalComponent.h"

#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"
Expand Down Expand Up @@ -567,14 +568,18 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire(

if (let HitDecal = PhysicalMaterial->GetRandomFirearmDecal(); IsValid(HitDecal))
{
GetWorld() | EUWorld::SpawnDecal{
.Material = HitDecal,
.DecalSize = PhysicalMaterial->GetFirearmDecalSize(),
.Location = LineHit.Location,
.Rotator = PhysicalMaterial->GetFirearmDecalRotation(LineHit.Normal),
.Owner = DamagedActor,
.Instigator = Character
};
var Decal = UGameplayStatics::SpawnDecalAttached(
HitDecal,
PhysicalMaterial->GetFirearmDecalSize(),
LineHit.GetComponent(),
NAME_None,
LineHit.Location,
PhysicalMaterial->GetFirearmDecalRotation(LineHit.ImpactNormal),
EAttachLocation::KeepWorldPosition,
Settings->DecalLifeSpan
);

Decal->SetFadeScreenSize(Settings->DecalFadeScreenSize);
}

if (let HitSound = PhysicalMaterial->GetRandomFirearmHitSound(); IsValid(HitSound))
Expand Down Expand Up @@ -608,15 +613,19 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire(

if (IsBackgroundHit)
{
GetWorld() | EUWorld::SpawnDecal{
.Material = BackgroundDecal,
.DecalSize = PhysicalMaterial->GetBackgroundDecalSize(),
.Location = PhysicalMaterial->GetBackgroundDecalLocation(
var Decal = UGameplayStatics::SpawnDecalAttached(
BackgroundDecal,
PhysicalMaterial->GetBackgroundDecalSize(),
BackgroundHit.GetComponent(),
NAME_None,
PhysicalMaterial->GetBackgroundDecalLocation(
BackgroundHit.Location, BackgroundHit.Normal),
.Rotator = PhysicalMaterial->GetBackgroundDecalRotation(BackgroundHit.Normal),
.Owner = LineHit.Actor.Get(),
.Instigator = Character
};
PhysicalMaterial->GetBackgroundDecalRotation(BackgroundHit.ImpactNormal),
EAttachLocation::KeepWorldPosition,
Settings->DecalLifeSpan
);

Decal->SetFadeScreenSize(Settings->DecalFadeScreenSize);
}
}
}
Expand Down