Create WeaponThrowable class
This commit is contained in:
parent
7c803eb3ff
commit
81c954dabb
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -14,4 +14,19 @@ 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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue