How to move sight when lean left/right in lyra

I’m making Q/E or leaning function in lyra, works like Q/E in Rainbow Six or Escape from Tarkov. And I need this ability could used by player and AI.
I know how to do leaning animation, but I don’t know how to make gun sight move left/right at the same time, No matter how I lean to left or right, the sight doesn’t move.
Can anyone give me a hint?

Just to clarify, it looks you want to create a “corner leaning/peaking”, not a locomotion leaning, is that correct?
Either way, you want to tilt the camera by changing the camera roll. Because Lyra uses Control Rotation Yaw, use the node Set Control Rotation and change the roll from there. This video might help you:
FPS leaning | Unreal engine 4/5 Tutorial - YouTube

Very, very easy. You open the Lyra project in Visual Studio, and in the file LyraCameraMode_ThirdPerson.h, you add a variable.

UPROPERTY(EditDefaultsOnly, Category = "Third Person")
FRotator RotatorOffset;

After that, in the LyraCameraMode_ThirdPerson.cpp file, you locate the UpdateView(float DeltaTime) function, and in the final adjustments, you add the line that adds the RotatorOffset to the camera rotation.

View.Rotation = View.Rotation + RotatorOffset;

Only a single line of the function has been modified.

void ULyraCameraMode_ThirdPerson::UpdateView(float DeltaTime)
{
	UpdateForTarget(DeltaTime);
	UpdateCrouchOffset(DeltaTime);

	FVector PivotLocation = GetPivotLocation() + CurrentCrouchOffset;
	FRotator PivotRotation = GetPivotRotation();

	PivotRotation.Pitch = FMath::ClampAngle(PivotRotation.Pitch, ViewPitchMin, ViewPitchMax);

	View.Location = PivotLocation;
	View.Rotation = PivotRotation;
	View.ControlRotation = View.Rotation;
	View.FieldOfView = FieldOfView;

	// Apply third person offset using pitch.
	if (!bUseRuntimeFloatCurves)
	{
		if (TargetOffsetCurve)
		{
			const FVector TargetOffset = TargetOffsetCurve->GetVectorValue(PivotRotation.Pitch);
			View.Location = PivotLocation + PivotRotation.RotateVector(TargetOffset);
		}
	}
	else
	{
		FVector TargetOffset(0.0f);

		TargetOffset.X = TargetOffsetX.GetRichCurveConst()->Eval(PivotRotation.Pitch);
		TargetOffset.Y = TargetOffsetY.GetRichCurveConst()->Eval(PivotRotation.Pitch);
		TargetOffset.Z = TargetOffsetZ.GetRichCurveConst()->Eval(PivotRotation.Pitch);

		View.Location = PivotLocation + PivotRotation.RotateVector(TargetOffset);
	}

	//Rotation adjustment
	View.Rotation = View.Rotation + RotatorOffset;
	// Adjust final desired camera location to prevent any penetration
	UpdatePreventPenetration(DeltaTime);
}

After that, you will need to create 2 files: CM_ThirdPerson_LookRight and CM_ThirdPerson_LookLeft. And each of them will need to have an ability to switch the cameras.

2 Likes