Implemented Explosive Functionality
Needs to be linked with AI TakeDamage when everything is merged
This commit is contained in:
parent
877f485fa4
commit
9d36fa7846
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f5563c101f81066dbb41a0b754402e01042647fdcf549bbdeeec92f0439b3230
|
||||
size 31653
|
3
EndlessVendetta/Content/Gadgets/BP_Grenade.uasset
Normal file
3
EndlessVendetta/Content/Gadgets/BP_Grenade.uasset
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8ff5fde4fbfe047c25915d65585f2437dba30915a42f654972b362d236ccf6f4
|
||||
size 42440
|
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:133db5845b20abcf5ffcb9bc6717757183a2440744b01ad1f038760335a5bea7
|
||||
size 40521
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9fccd918d154abe44f38ff143101e53cd24b3e942af805172cf6ffe84b7e7cb3
|
||||
size 109934
|
||||
oid sha256:7deabddf98ca24dc431c4e0f2c25ba9b0d9edf03e2637c6a3dc37a1ccf7e8068
|
||||
size 109849
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:04bfe587aa943c22a21e10962ddfb29aa185a165a9b1862aebbb012c532e5b8f
|
||||
oid sha256:2bc44125551b89f13cdffde72a42c09685d26b6bbaa3ce8d28858ab14d83c0dc
|
||||
size 108254
|
||||
|
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Blueprints/Blueprint_CeilingLight.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Blueprints/Blueprint_CeilingLight.uasset
(Stored with Git LFS)
Binary file not shown.
@ -3,6 +3,9 @@
|
||||
|
||||
#include "Explosive.h"
|
||||
|
||||
#include "CollisionDebugDrawingPublic.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
// Sets default values
|
||||
AExplosive::AExplosive()
|
||||
{
|
||||
@ -16,8 +19,14 @@ void AExplosive::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("An explosive has Spawned in ;)"));
|
||||
|
||||
if (ExplosionDelayInSeconds <= 0)
|
||||
{
|
||||
Explosion();
|
||||
return;
|
||||
}
|
||||
|
||||
FTimerHandle ExplosionHandle;
|
||||
GetWorld()->GetTimerManager().SetTimer(ExplosionHandle, this, &AExplosive::Explosion, ExplosionDelayInSeconds);
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
@ -27,3 +36,52 @@ void AExplosive::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
void AExplosive::Explosion()
|
||||
{
|
||||
float PitchAngleIncrement = 180.f / ShrapnelPitchDensity;
|
||||
float YawAngleIncrement = 360.f / ShrapnelYawDensity;
|
||||
|
||||
FHitResult OutHit;
|
||||
FCollisionQueryParams QueryParams = FCollisionQueryParams::DefaultQueryParam;
|
||||
QueryParams.bTraceComplex = false;
|
||||
QueryParams.AddIgnoredActor(this);
|
||||
FVector LT_Start = GetActorLocation();
|
||||
|
||||
for(int y = 1; y <= ShrapnelPitchDensity; y++)
|
||||
{
|
||||
for (int x = 1; x <= ShrapnelYawDensity; x++)
|
||||
{
|
||||
FRotator ShrapnelRotation = FRotator(-90.f + (y * PitchAngleIncrement), x * YawAngleIncrement, 0.f);
|
||||
FVector LT_End = LT_Start + (UKismetMathLibrary::GetForwardVector(ShrapnelRotation) * ShrapnelTravelDistance);
|
||||
bool HitSomething = GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams);
|
||||
|
||||
if (DrawDebugLines) DrawShrapnelDebugLines(HitSomething, LT_Start, LT_End, OutHit.ImpactPoint);
|
||||
if (!HitSomething || !OutHit.GetActor()->ActorHasTag(FName("Enemy")) || OutHit.GetActor()->ActorHasTag(FName("Dead"))) continue;
|
||||
|
||||
float HitDistance = FVector::Distance(LT_Start, OutHit.ImpactPoint);
|
||||
float DamageToApply = ShrapnelDamage;
|
||||
if (HitDistance > ShrapnelDamageFalloffDistance)
|
||||
{
|
||||
// Damage linearly decrease from falloff distance to maximum travel distance, using straight line equation y = mx + c
|
||||
float Magnitude = ShrapnelDamage / (ShrapnelDamageFalloffDistance - ShrapnelTravelDistance);
|
||||
float DMG_Intercept = ShrapnelDamage - (Magnitude * ShrapnelDamageFalloffDistance);
|
||||
DamageToApply = (Magnitude * HitDistance) + DMG_Intercept;
|
||||
}
|
||||
// When merged, call philips take damage function here
|
||||
UE_LOG(LogTemp, Warning, TEXT("A shrapnel piece hit %s, dealing %f damage"), *OutHit.GetActor()->GetName(), DamageToApply);
|
||||
}
|
||||
}
|
||||
PlayExplosionEffects();
|
||||
}
|
||||
|
||||
void AExplosive::DrawShrapnelDebugLines(bool HitSomething, FVector StartVector, FVector EndVector, FVector ImpactPoint)
|
||||
{
|
||||
if (!HitSomething)
|
||||
{
|
||||
DrawDebugLine(GetWorld(), StartVector, EndVector, FColor::Green, false, 5, 0, 2);
|
||||
return;
|
||||
}
|
||||
DrawDebugLine(GetWorld(), ImpactPoint, EndVector, FColor::Red, false, 5, 0, 2);
|
||||
DrawDebugLine(GetWorld(), StartVector, ImpactPoint, FColor::Green, false, 5, 0, 2);
|
||||
}
|
||||
|
||||
|
@ -10,16 +10,53 @@ UCLASS()
|
||||
class ENDLESSVENDETTA_API AExplosive : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AExplosive();
|
||||
|
||||
void DrawShrapnelDebugLines(bool HitSomething, FVector StartVector, FVector EndVector, FVector ImpactPoint);
|
||||
|
||||
protected:
|
||||
// Maximum amount of damage dealt by an individual piece of shrapnel
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
float ShrapnelDamage = 10;
|
||||
|
||||
// Number of shrapnel pieces uniformly spread around the Y axis
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
int ShrapnelPitchDensity = 40;
|
||||
|
||||
// Number of shrapnel pieces uniformly spread around the Z axis
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
int ShrapnelYawDensity = 40;
|
||||
|
||||
// How far shrapnel should travel from origin point, given its not obstructed along its path
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
float ShrapnelTravelDistance = 600;
|
||||
|
||||
// After what distance travelled should shrapnel damage start to decrease
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
float ShrapnelDamageFalloffDistance = 200;
|
||||
|
||||
// Delay from spawning in before explosion happens
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
|
||||
float ExplosionDelayInSeconds = 0;
|
||||
|
||||
/**
|
||||
* Should debug lines be drawn to show planned travel trajectory of each
|
||||
* shrapnel piece in red, and actual travelled shrapnel trajectory in green
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, Category = "Explosion")
|
||||
bool DrawDebugLines = false;
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Explosion")
|
||||
void PlayExplosionEffects();
|
||||
|
||||
void Explosion();
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AExplosive();
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user