Fix Machinegun Throwable

This commit is contained in:
baz 2024-05-30 21:01:41 +01:00
parent 2b5d67346a
commit 2fffd64ae8
12 changed files with 57 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Weapons/Machinegun/BP_Machinegun.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Weapons/Machinegun/BP_MachinegunThrowable.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,15 @@ AThrowable::AThrowable()
StaticMeshComponent->SetGenerateOverlapEvents(true); StaticMeshComponent->SetGenerateOverlapEvents(true);
StaticMeshComponent->SetNotifyRigidBodyCollision(true); StaticMeshComponent->SetNotifyRigidBodyCollision(true);
SetRootComponent(StaticMeshComponent); SetRootComponent(StaticMeshComponent);
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
SphereComponent->SetSphereRadius(25.0f, true);
SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe);
SphereComponent->SetCollisionObjectType(ECC_WorldDynamic);
SphereComponent->SetSimulatePhysics(true);
SphereComponent->SetGenerateOverlapEvents(true);
SphereComponent->SetNotifyRigidBodyCollision(true);
SphereComponent->SetupAttachment(RootComponent);
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned

View File

@ -17,9 +17,8 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, meta = (ClampMin = "0.0", ClampMax = "1.0")) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, meta = (ClampMin = "0.0", ClampMax = "1.0"))
float ImpulseAngle = 0.5f; float ImpulseAngle = 0.5f;
protected: UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USphereComponent* SphereComponent; USphereComponent* SphereComponent;
public: public:

View File

@ -28,8 +28,8 @@ class NAKATOMI_API AWeapon : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(BlueprintReadWrite) UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
USkeletalMeshComponent* WeaponSkeletalMeshComponent; USkeletalMeshComponent* WeaponSkeletalMeshComponent;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)

View File

@ -9,7 +9,7 @@
AWeaponThrowable::AWeaponThrowable() AWeaponThrowable::AWeaponThrowable()
{ {
WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh Component")); WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh Component"));
WeaponSkeletalMeshComponent->SetCollisionProfileName(FName("BlockAll")); WeaponSkeletalMeshComponent->SetCollisionProfileName(FName("OverlapAll"));
WeaponSkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); WeaponSkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
WeaponSkeletalMeshComponent->SetCollisionObjectType(ECC_WorldDynamic); WeaponSkeletalMeshComponent->SetCollisionObjectType(ECC_WorldDynamic);
WeaponSkeletalMeshComponent->SetSimulatePhysics(true); WeaponSkeletalMeshComponent->SetSimulatePhysics(true);
@ -22,7 +22,7 @@ void AWeaponThrowable::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
WeaponSkeletalMeshComponent->OnComponentHit.AddDynamic(this, &AWeaponThrowable::OnOverlapBegin); WeaponSkeletalMeshComponent->OnComponentBeginOverlap.AddDynamic(this, &AWeaponThrowable::OnSphereBeginOverlap);
auto playerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); auto playerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
auto playerForwardVector = playerCharacter->GetActorForwardVector(); auto playerForwardVector = playerCharacter->GetActorForwardVector();
@ -43,3 +43,20 @@ void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh)
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce); WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce);
} }
} }
void AWeaponThrowable::OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult)
{
if (!OtherActor->ActorHasTag(FName("Player")) && OtherActor != this)
{
if (HealthComponent)
{
HealthComponent->TakeDamage(this, HealthComponent->GetMaxHealth(), nullptr,
nullptr, this);
}
}
}

View File

@ -28,4 +28,13 @@ protected:
public: public:
void SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh); void SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh);
private:
UFUNCTION()
void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult);
}; };