Files
BallisticsDocs/Source/EasyBallistics/Public/EBBallisticImpactComponent.h
T
2025-07-02 22:40:58 -07:00

91 lines
2.7 KiB
C++

// Copyright 2016 Mookie. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PhysicalMaterials/PhysicalMaterial.h"
#include "EBBulletProperties.h"
#include "EBMaterialResponseMap.h"
#include "EBBallisticImpactComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams(FOnBallisticImpact,
FVector, ImpactLocation,
FVector, ImpactNormal,
UPhysicalMaterial*, HitMaterial,
float, PenetrationDepth,
bool, bDidPenetrate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnBallisticRicochet,
FVector, RicochetLocation,
FVector, RicochetDirection,
UPhysicalMaterial*, HitMaterial,
float, EnergyRetained);
UCLASS(ClassGroup=(Ballistics), meta=(BlueprintSpawnableComponent))
class EASYBALLISTICS_API UEBBallisticImpactComponent : public UActorComponent
{
GENERATED_BODY()
public:
UEBBallisticImpactComponent();
// Events
UPROPERTY(BlueprintAssignable, Category = "Ballistics Events")
FOnBallisticImpact OnBallisticImpact;
UPROPERTY(BlueprintAssignable, Category = "Ballistics Events")
FOnBallisticRicochet OnBallisticRicochet;
// Configuration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ballistics")
UEBMaterialResponseMap* MaterialResponseMap;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ballistics")
bool bEnableBallisticCalculations = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ballistics")
bool bUseMathematicalPenetration = false;
// Blueprint callable functions
UFUNCTION(BlueprintCallable, Category = "Ballistics")
FVector CalculateBallisticImpact(
const FVector& ImpactLocation,
const FVector& ProjectileVelocity,
const FMathematicalBulletProperties& BulletProperties,
UPhysicalMaterial* HitMaterial,
float& OutPenetrationDepth,
bool& bOutDidPenetrate,
FVector& OutExitLocation
);
UFUNCTION(BlueprintCallable, Category = "Ballistics")
FVector CalculateRicochet(
const FVector& ImpactLocation,
const FVector& ImpactNormal,
const FVector& ProjectileVelocity,
const FMathematicalBulletProperties& BulletProperties,
UPhysicalMaterial* HitMaterial,
float& OutEnergyRetained,
bool& bOutDidRicochet
);
UFUNCTION(BlueprintCallable, Category = "Ballistics")
UEBMaterialPropertiesAsset* GetMaterialProperties(UPhysicalMaterial* PhysicalMaterial);
UFUNCTION(BlueprintCallable, Category = "Ballistics")
FEBMaterialResponseMapEntry GetMaterialResponse(UPhysicalMaterial* PhysicalMaterial);
protected:
virtual void BeginPlay() override;
private:
FVector CalculatePenetrationVector(
const FVector& ImpactLocation,
const FVector& ImpactNormal,
const FVector& ProjectileVelocity,
float PenetrationDepth
);
float CalculateImpactAngle(const FVector& ProjectileVelocity, const FVector& SurfaceNormal);
};