Create WeaponThrowable class

This commit is contained in:
baz 2023-09-18 02:27:56 +01:00
parent 7c803eb3ff
commit 81c954dabb
2 changed files with 44 additions and 0 deletions

View File

@ -3,3 +3,32 @@
#include "WeaponThrowable.h"
#include "PlayerCharacter.h"
#include "Kismet/GameplayStatics.h"
AWeaponThrowable::AWeaponThrowable()
{
WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(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<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector();
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector);
}
void AWeaponThrowable::SetWeaponSkeletalMesh(USkeletalMesh* SkeletalMesh)
{
WeaponSkeletalMeshComponent->SetSkeletalMesh(SkeletalMesh);
auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector();
WeaponSkeletalMeshComponent->AddImpulse(playerForwardVector);
}

View File

@ -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);
};