From 7cdb9b1c695a53aeb81a144c71371a3f7538e5f6 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 19 Sep 2023 02:19:23 +0100 Subject: [PATCH] Add Impulse Angle and Force variables to Throwables --- Source/Nakatomi/Throwable.cpp | 3 ++- Source/Nakatomi/Throwable.h | 8 ++++++++ Source/Nakatomi/WeaponThrowable.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/Nakatomi/Throwable.cpp b/Source/Nakatomi/Throwable.cpp index 864de29..93a8ed4 100644 --- a/Source/Nakatomi/Throwable.cpp +++ b/Source/Nakatomi/Throwable.cpp @@ -32,7 +32,8 @@ void AThrowable::BeginPlay() SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AThrowable::OnOverlapBegin); auto playerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerForwardVector = playerCharacter->GetActorForwardVector(); - StaticMeshComponent->AddImpulse(playerForwardVector); + playerForwardVector.Z = ImpulseAngle; + StaticMeshComponent->AddImpulse(playerForwardVector * ImpulseForce); } void AThrowable::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, diff --git a/Source/Nakatomi/Throwable.h b/Source/Nakatomi/Throwable.h index 6d0fe27..b6f58b0 100644 --- a/Source/Nakatomi/Throwable.h +++ b/Source/Nakatomi/Throwable.h @@ -11,6 +11,14 @@ class NAKATOMI_API AThrowable : public AExplosiveActor { GENERATED_BODY() +public: + + UPROPERTY(meta = (ClampMin = "0.0")) + float ImpulseForce = 10000.f; + + UPROPERTY(meta = (ClampMin = "0.0", ClampMax = "1.0")) + float ImpulseAngle = 0.5f; + private: UPROPERTY() diff --git a/Source/Nakatomi/WeaponThrowable.cpp b/Source/Nakatomi/WeaponThrowable.cpp index 892b3d3..4edc2aa 100644 --- a/Source/Nakatomi/WeaponThrowable.cpp +++ b/Source/Nakatomi/WeaponThrowable.cpp @@ -21,7 +21,8 @@ void AWeaponThrowable::BeginPlay() auto playerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerForwardVector = playerCharacter->GetActorForwardVector(); - WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); + playerForwardVector.Z = ImpulseAngle; + WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce); } void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh) @@ -30,5 +31,6 @@ void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh) auto playerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerForwardVector = playerCharacter->GetActorForwardVector(); - WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); + playerForwardVector.Z = ImpulseAngle; + WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce); }