Can you snip that code from the headers/source for the First Person Camera mode? The link you have to post #15 doesn’t show any code.
Echoing @JordonHynes here. Anyone have the original code snippet?
i’m noob in c++, i’m just copied thirdpersoncamera.cpp and .h, and added code that written here
How To Use CUSTOM CAMERA Placement With Lyra Characters | UE5.2 | - YouTube This Solution Solves Child Camera Component’s And Removes The Dependency For C++ Camera Children
For those who has T-POSE issue, I have implemented first person camera mode class as below. The logic is like for the first tick setting camera a little bit distant to character (like detaching from character and moving out) then in the next tick attaching it to the socket (FP_Camera in my case).
In my case
h. file;
#pragma once
#include "Camera/LyraCameraMode.h"
#include "LyraCameraMode_FirstPerson.generated.h"
/**
* ULyraCameraMode_FirstPerson
*
* A basic first person camera mode.
*/
UCLASS(Abstract, Blueprintable)
class ULyraCameraMode_FirstPerson : public ULyraCameraMode
{
GENERATED_BODY()
public:
ULyraCameraMode_FirstPerson();
protected:
virtual void UpdateView(float DeltaTime) override;
virtual void OnActivation() override;
virtual FVector GetPivotLocation() const override;
private:
void OnActivationNextTick();
bool bIsFirstTick;
};
cpp. file;
#include "Camera/LyraCameraMode_FirstPerson.h"
#include "GameFramework/Character.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraCameraMode_FirstPerson)
ULyraCameraMode_FirstPerson::ULyraCameraMode_FirstPerson()
{
}
void ULyraCameraMode_FirstPerson::OnActivation()
{
bIsFirstTick = true;
GetWorld()->GetTimerManager().SetTimerForNextTick(this, &ULyraCameraMode_FirstPerson::OnActivationNextTick);
}
void ULyraCameraMode_FirstPerson::UpdateView(float DeltaTime)
{
FVector PivotLocation = GetPivotLocation();
FRotator PivotRotation = GetPivotRotation();
PivotRotation.Pitch = FMath::ClampAngle(PivotRotation.Pitch, ViewPitchMin, ViewPitchMax);
View.Location = PivotLocation;
View.Rotation = PivotRotation;
View.ControlRotation = View.Rotation;
View.FieldOfView = FieldOfView;
if (bIsFirstTick)
{
// This will simulate the camera like it has a distance to the character at the first tick, play with -200.f if it doesn't work
View.Location = PivotLocation + PivotRotation.RotateVector(FVector(-200.f, 0.f, 0.f));
}
}
FVector ULyraCameraMode_FirstPerson::GetPivotLocation() const
{
const AActor* TargetActor = GetTargetActor();
check(TargetActor);
if (const APawn* TargetPawn = Cast<APawn>(TargetActor))
{
// Get mesh socket location for first person camera
if (const ACharacter* TargetCharacter = Cast<ACharacter>(TargetPawn))
{
return TargetCharacter->GetMesh()->GetSocketLocation("FP_Camera");
}
return TargetPawn->GetPawnViewLocation();
}
return TargetActor->GetActorLocation();
}
void ULyraCameraMode_FirstPerson::OnActivationNextTick()
{
bIsFirstTick = false;
}
T-Pose is solved by selecting the Mesh and setting Always Tick Pose and Refresh Bones
under Optimization → Visibility Based Anim Tick Option. Otherwise bones won’t move until visible.
Hey, I made a Game Feature Plugin for Lyra that lets you go into first person, it’s free over at GitHub. It’s not perfect but it may help for reference!
GitHub:
Demo:
-Phil
Afoot Games
did you ever resolve this?
Those lines are the head mesh, because it’s still visible.
Preferably you’d have a separate head mesh you can hide for the player.
I used your work a lot as a reference, thanks man! I also want to share my own attempt at figuring this out:
Github:
Demo:
I basically used Afoot’s work and integrate it with Octahedron’s procedural FP Animations. This is not a true first-person setup, so we have third-person meshes and first-person meshes and can toggle between the two.