Prepared player camera setup for animation

Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
TjgL 2025-02-23 11:14:25 +01:00
parent a1c4f3725c
commit 8d2fe05e83
8 changed files with 49 additions and 29 deletions

BIN
Content/Legumix/Player/BP_Play.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Legumix/Player/BP_Player.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:00552f5c9ac368a603670e87a704df5ad1114f35d30cc20694e6cb766fb2e8f3
size 65622016
oid sha256:82f689c996d185b6a7b87026be21593479634e4119b31638a640b5bda185d576
size 65548288

View File

@ -13,21 +13,19 @@
ALMPlayer::ALMPlayer()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(RootComponent);
Camera->bUsePawnControlRotation = true;
Camera->SetRelativeLocation(FVector(20, 0, 90));
ArmsMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Arms Mesh"));
ArmsMesh->SetupAttachment(Camera);
// Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
// Camera->SetupAttachment(RootComponent);
// Camera->bUsePawnControlRotation = true;
// Camera->SetRelativeLocation(FVector(20, 0, 90));
//
// ArmsMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Arms Mesh"));
// ArmsMesh->SetupAttachment(Camera);
SpreadStream = FRandomStream(FMath::Rand());
}
// Called when the game starts or when spawned
void ALMPlayer::BeginPlay()
{
Super::BeginPlay();
@ -71,7 +69,7 @@ void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager)
}
WeaponManager = Manager;
WeaponManager->Initialize(ArmsMesh);
WeaponManager->Initialize(GetArms());
}
void ALMPlayer::PlayAnimation(UAnimMontage* Animation)
@ -122,15 +120,31 @@ void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
}
}
FVector ALMPlayer::GetWeaponFiringOrigin() const
FVector ALMPlayer::GetWeaponFiringOrigin()
{
if (!Camera)
if (!GetCam())
{
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.f, FColor::Silver, TEXT("No camera ???"));
return FVector::ZeroVector;
}
return Camera->GetComponentTransform().GetLocation();
return GetCam()->GetComponentTransform().GetLocation();
}
FVector ALMPlayer::GetAimVector() const { return Camera->GetForwardVector(); }
FVector ALMPlayer::GetAimVector() { return GetCam()->GetForwardVector(); }
UCameraComponent* ALMPlayer::GetCam()
{
if (!Camera)
Camera = GetCamera();
return Camera;
}
USkeletalMeshComponent* ALMPlayer::GetArms()
{
if (!ArmsMesh)
ArmsMesh = GetArmsBP();
return ArmsMesh;
}

View File

@ -60,10 +60,10 @@ public:
void FireBullets(const FLMBulletInfo Settings);
UFUNCTION(BlueprintCallable)
FVector GetWeaponFiringOrigin() const;
FVector GetWeaponFiringOrigin();
UFUNCTION(BlueprintCallable)
FVector GetAimVector() const;
FVector GetAimVector();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void WeaponFired();
@ -83,6 +83,15 @@ public:
UFUNCTION(BlueprintImplementableEvent, Category=Legumix)
void OnReload();
public:
UFUNCTION(BlueprintImplementableEvent)
UCameraComponent* GetCamera();
UCameraComponent* GetCam();
UFUNCTION(BlueprintImplementableEvent)
USkeletalMeshComponent* GetArmsBP();
USkeletalMeshComponent* GetArms();
private:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
TObjectPtr<ULMWeaponManager> WeaponManager;