Attempt to implement damage flash for enemy ships
This commit is contained in:
Binary file not shown.
BIN
Content/Main.umap
LFS
BIN
Content/Main.umap
LFS
Binary file not shown.
BIN
Content/Materials/xwingCanopy.uasset
LFS
Normal file
BIN
Content/Materials/xwingCanopy.uasset
LFS
Normal file
Binary file not shown.
@@ -61,6 +61,8 @@ void AEnemySpaceship::BeginPlay()
|
|||||||
bInitializedFlank = false;
|
bInitializedFlank = false;
|
||||||
LastFlankUpdateTime = 0.0f;
|
LastFlankUpdateTime = 0.0f;
|
||||||
CurrentFlankTarget = GetActorLocation();
|
CurrentFlankTarget = GetActorLocation();
|
||||||
|
|
||||||
|
InitializeDynamicMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify Tick function to include flanking behavior
|
// Modify Tick function to include flanking behavior
|
||||||
@@ -507,6 +509,57 @@ void AEnemySpaceship::ResetFire()
|
|||||||
bCanFire = true;
|
bCanFire = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AEnemySpaceship::InitializeDynamicMaterial()
|
||||||
|
{
|
||||||
|
if (EnemyMesh)
|
||||||
|
{
|
||||||
|
// Store the original material
|
||||||
|
OriginalMaterial = EnemyMesh->GetMaterial(0);
|
||||||
|
|
||||||
|
if (OriginalMaterial)
|
||||||
|
{
|
||||||
|
// Create dynamic material instance only once
|
||||||
|
DynamicMaterialInstance = UMaterialInstanceDynamic::Create(OriginalMaterial, this);
|
||||||
|
if (DynamicMaterialInstance)
|
||||||
|
{
|
||||||
|
// Apply the dynamic material instance to the mesh
|
||||||
|
EnemyMesh->SetMaterial(0, DynamicMaterialInstance);
|
||||||
|
|
||||||
|
// Initialize flash color to transparent
|
||||||
|
DynamicMaterialInstance->SetVectorParameterValue("FlashColor", FLinearColor(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEnemySpaceship::ApplyDamageFlash()
|
||||||
|
{
|
||||||
|
// Only set the flash color if we have a valid dynamic material instance
|
||||||
|
if (DynamicMaterialInstance)
|
||||||
|
{
|
||||||
|
// Set the flash color
|
||||||
|
DynamicMaterialInstance->SetVectorParameterValue("FlashColor", DamageFlashColor);
|
||||||
|
|
||||||
|
// Set timer to reset the flash
|
||||||
|
GetWorldTimerManager().SetTimer(
|
||||||
|
DamageFlashTimerHandle,
|
||||||
|
this,
|
||||||
|
&AEnemySpaceship::ResetDamageFlash,
|
||||||
|
DamageFlashDuration,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEnemySpaceship::ResetDamageFlash()
|
||||||
|
{
|
||||||
|
// Reset the flash color only if we have a valid dynamic material instance
|
||||||
|
if (DynamicMaterialInstance)
|
||||||
|
{
|
||||||
|
DynamicMaterialInstance->SetVectorParameterValue("FlashColor", FLinearColor(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float AEnemySpaceship::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent,
|
float AEnemySpaceship::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent,
|
||||||
AController* EventInstigator, AActor* DamageCauser)
|
AController* EventInstigator, AActor* DamageCauser)
|
||||||
{
|
{
|
||||||
@@ -521,6 +574,9 @@ float AEnemySpaceship::TakeDamage(float DamageAmount, FDamageEvent const& Damage
|
|||||||
FString::Printf(TEXT("Enemy Hit! Health: %f"), CurrentHealth));
|
FString::Printf(TEXT("Enemy Hit! Health: %f"), CurrentHealth));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply visual damage effects
|
||||||
|
ApplyDamageFlash();
|
||||||
|
|
||||||
// When damaged, prefer retreat or strafe behaviors temporarily
|
// When damaged, prefer retreat or strafe behaviors temporarily
|
||||||
if (FMath::RandBool())
|
if (FMath::RandBool())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -109,6 +109,20 @@ protected:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
|
||||||
float FlankingFrequency = 0.6f; // Increased chance of flanking (was 0.4f)
|
float FlankingFrequency = 0.6f; // Increased chance of flanking (was 0.4f)
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UMaterialInterface* OriginalMaterial;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UMaterialInstanceDynamic* DynamicMaterialInstance;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Effects")
|
||||||
|
FLinearColor DamageFlashColor = FLinearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Effects")
|
||||||
|
float DamageFlashDuration = 0.1f;
|
||||||
|
|
||||||
|
FTimerHandle DamageFlashTimerHandle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
@@ -164,4 +178,8 @@ private:
|
|||||||
float LastFlankUpdateTime;
|
float LastFlankUpdateTime;
|
||||||
FVector CurrentFlankTarget;
|
FVector CurrentFlankTarget;
|
||||||
bool bInitializedFlank;
|
bool bInitializedFlank;
|
||||||
|
|
||||||
|
void InitializeDynamicMaterial();
|
||||||
|
void ApplyDamageFlash();
|
||||||
|
void ResetDamageFlash();
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user