Add attach weapon to hand socket

This commit is contained in:
Louis Hobbs 2023-01-12 23:17:34 +00:00
parent 7c979f613a
commit ada4178123
1 changed files with 24 additions and 3 deletions

View File

@ -51,6 +51,7 @@ void APlayerCharacter::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
DefaultMovementSpeed = GetCharacterMovement()->MaxWalkSpeed; DefaultMovementSpeed = GetCharacterMovement()->MaxWalkSpeed;
SetInventoryToDefault();
} }
// Called every frame // Called every frame
@ -281,8 +282,14 @@ void APlayerCharacter::InventoryDecrement()
AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon) AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon)
{ {
// TODO: All logic to spawn weapon into level then deactivate it until needed FActorSpawnParameters SpawnParameters;
return nullptr; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AWeapon* Weapon = GetWorld()->SpawnActor<AWeapon>(weapon, SpawnParameters);
Weapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, "WeaponHand");
Weapon->SetActorEnableCollision(false);
Weapon->SetActorHiddenInGame(true);
return Weapon;
} }
AWeapon* APlayerCharacter::GetCurrentWeapon() AWeapon* APlayerCharacter::GetCurrentWeapon()
@ -292,5 +299,19 @@ AWeapon* APlayerCharacter::GetCurrentWeapon()
void APlayerCharacter::SetCurrentWeapon(AWeapon* weapon) 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);
}
} }