Im having issues with coding an ability for the player to reset the camera behind the player when needed. I was going for something that the souls games have with their camera and how you can press the r3 stick to reset the camera. I saw people do it in blueprints.
I tried to convert the blueprint into c++, this is what i did.
Uplayable_camera::Uplayable_camera()
{
SetFieldOfView(FOV);
reset_curve = NewObject<UCurveFloat>(this, TEXT("reset_curve"));
reset_curve->FloatCurve.AddKey(0.f, 0.f);
reset_curve->FloatCurve.AddKey(0.5f, 1.f);
reset_timeline = FTimeline{};
FOnTimelineFloat update_call;
update_call.BindUFunction(this, TEXT("handle_camera_reset"));
reset_timeline.AddInterpFloat(reset_curve, update_call);
reset_timeline.SetLooping(false);
reset_timeline.SetTimelineLength(0.50);
reset_timeline.PlayFromStart();
}
void Uplayable_camera::BeginPlay()
{
Super::BeginPlay();
playerController = GetWorld()->GetFirstPlayerController();
CH = Cast<ACharacter>(GetOwner());
BCH = Cast<Abase_character>(GetOwner());
reset_timeline.PlayFromStart();
}
void Uplayable_camera::handle_camera_reset()
{
if (BCH && arrow_ref)
{
float Alpha = 0.0f;
FRotator new_rotation = FMath::Lerp(BCH->GetControlRotation(), arrow_ref->GetComponentRotation(), Alpha);
playerController->SetControlRotation(new_rotation);
}
}
void Uplayable_camera::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
reset_timeline.TickTimeline(DeltaTime);
}
But of course, it doesnt work. What can I do to achive the deseried outcome?