From ff8e947a4e2df99a043b56b79e4c3c9d08ad8478 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 18 Sep 2023 02:28:31 +0100 Subject: [PATCH] Add functionality to ThrowWeaponCallback --- Source/Nakatomi/PlayerCharacter.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 5e4d8b0..d0561a3 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -13,6 +13,7 @@ #include "GameFramework/CharacterMovementComponent.h" #include "InputMappingContext.h" #include "EnemyCharacter.h" +#include "WeaponThrowable.h" #define COLLISION_WEAPON ECC_GameTraceChannel1 @@ -576,11 +577,20 @@ float APlayerCharacter::GetWeaponSpread() void APlayerCharacter::ThrowWeaponCallback() { - auto throwable = ThrowThrowable(); + FVector Location; + FVector BoxExtent; + GetActorBounds(true, Location, BoxExtent, false); + FVector SpawnLocation = FVector(Location.X, Location.Y + (BoxExtent.Y / 2), Location.Z + (BoxExtent.Z / 2)); + SpawnLocation += GetTransform().GetLocation(); - // TODO: Set the collision size to the size of the static mesh in the throwable - // throwable->GetSphereComponent()->SetSphereRadius(); + if (TSubclassOf WeaponThrowableTemplate = GetCurrentWeapon()->GetWeaponThrowableTemplate()) + { + AWeaponThrowable* Throwable = GetWorld()->SpawnActor( + WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator); + + Throwable->SetWeaponSkeletalMesh(GetCurrentWeapon()->GetSkeletalMesh()); + } } void APlayerCharacter::ThrowExplosiveCallback()