diff --git a/Source/Nakatomi/WeaponThrowable.cpp b/Source/Nakatomi/WeaponThrowable.cpp index f606bf6..892b3d3 100644 --- a/Source/Nakatomi/WeaponThrowable.cpp +++ b/Source/Nakatomi/WeaponThrowable.cpp @@ -3,3 +3,32 @@ #include "WeaponThrowable.h" +#include "PlayerCharacter.h" +#include "Kismet/GameplayStatics.h" + +AWeaponThrowable::AWeaponThrowable() +{ + WeaponSkeletalMeshComponent = CreateDefaultSubobject(TEXT("Skeletal Mesh Component")); + WeaponSkeletalMeshComponent->SetCollisionProfileName(FName("PhysicsActor")); + WeaponSkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); + WeaponSkeletalMeshComponent->SetSimulatePhysics(true); + SetRootComponent(WeaponSkeletalMeshComponent); +} + +void AWeaponThrowable::BeginPlay() +{ + Super::BeginPlay(); + + auto playerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); + auto playerForwardVector = playerCharacter->GetActorForwardVector(); + WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); +} + +void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh) +{ + WeaponSkeletalMeshComponent->SetSkeletalMesh(SkeletalMesh); + + auto playerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); + auto playerForwardVector = playerCharacter->GetActorForwardVector(); + WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector); +} diff --git a/Source/Nakatomi/WeaponThrowable.h b/Source/Nakatomi/WeaponThrowable.h index a017a41..f1c89bb 100644 --- a/Source/Nakatomi/WeaponThrowable.h +++ b/Source/Nakatomi/WeaponThrowable.h @@ -13,5 +13,20 @@ UCLASS() class NAKATOMI_API AWeaponThrowable : public AThrowable { GENERATED_BODY() + +public: + + USkeletalMeshComponent* WeaponSkeletalMeshComponent; +public: + // Sets default values for this actor's properties + AWeaponThrowable(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + + void SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh); };