Add Impulse Angle and Force variables to Throwables

This commit is contained in:
baz 2023-09-19 02:19:23 +01:00
parent 27fc0d5212
commit 7cdb9b1c69
3 changed files with 14 additions and 3 deletions

View File

@ -32,7 +32,8 @@ void AThrowable::BeginPlay()
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AThrowable::OnOverlapBegin); SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AThrowable::OnOverlapBegin);
auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector(); auto playerForwardVector = playerCharacter->GetActorForwardVector();
StaticMeshComponent->AddImpulse(playerForwardVector); playerForwardVector.Z = ImpulseAngle;
StaticMeshComponent->AddImpulse(playerForwardVector * ImpulseForce);
} }
void AThrowable::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void AThrowable::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,

View File

@ -11,6 +11,14 @@ class NAKATOMI_API AThrowable : public AExplosiveActor
{ {
GENERATED_BODY() 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: private:
UPROPERTY() UPROPERTY()

View File

@ -21,7 +21,8 @@ void AWeaponThrowable::BeginPlay()
auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector(); auto playerForwardVector = playerCharacter->GetActorForwardVector();
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); playerForwardVector.Z = ImpulseAngle;
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce);
} }
void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh) void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh)
@ -30,5 +31,6 @@ void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh)
auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector(); auto playerForwardVector = playerCharacter->GetActorForwardVector();
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); playerForwardVector.Z = ImpulseAngle;
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector * ImpulseForce);
} }