From ada417812305f605f880dcf71cf4267566f56f70 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Thu, 12 Jan 2023 23:17:34 +0000 Subject: [PATCH] Add attach weapon to hand socket --- Source/Nakatomi/PlayerCharacter.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 412a6cb..05a5033 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -51,6 +51,7 @@ void APlayerCharacter::BeginPlay() Super::BeginPlay(); DefaultMovementSpeed = GetCharacterMovement()->MaxWalkSpeed; + SetInventoryToDefault(); } // Called every frame @@ -281,8 +282,14 @@ void APlayerCharacter::InventoryDecrement() AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf weapon) { - // TODO: All logic to spawn weapon into level then deactivate it until needed - return nullptr; + FActorSpawnParameters SpawnParameters; + SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + AWeapon* Weapon = GetWorld()->SpawnActor(weapon, SpawnParameters); + Weapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, "WeaponHand"); + Weapon->SetActorEnableCollision(false); + Weapon->SetActorHiddenInGame(true); + + return Weapon; } AWeapon* APlayerCharacter::GetCurrentWeapon() @@ -292,5 +299,19 @@ AWeapon* APlayerCharacter::GetCurrentWeapon() void APlayerCharacter::SetCurrentWeapon(AWeapon* weapon) { - // TODO: Add setting weapon logic here + if (CurrentWeapon == weapon) + { + return; + } + + if (CurrentWeapon) + { + CurrentWeapon->SetActorHiddenInGame(true); + } + + if (weapon) + { + CurrentWeapon = weapon; + CurrentWeapon->SetActorHiddenInGame(false); + } }