前进时改变 FOV(视野)

Changing FOV(Field of view) while moving forward

我有情况。我想在前进的同时平稳地改变 FOV。在父 class 的相机设置中,我设置默认值:

FollowCamera->FieldOfView = 90.0f;

然后在MoveForward函数中我这样设置

void AStarMotoVehicle::MoveForward(float Axis)
{
    if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
    { 
        //Angle of direction of camera on Yaw
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
    AddMovementInput(Direction, Axis);

    FollowCamera->FieldOfView = 140.0f;
    }

实际上它可以工作,所以当我向前移动时,FOV 变为 140,但它工作得非常粗略并且立即发生。我想从90到140顺利完成。 你能帮我吗?

FInterpTo 会为您做这个: https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FMath/FInterpTo/index.html

每次调用“MoveForward”,fov都会增加到140。 到slow/speed过渡,decrease/increaseInterpSpeed值

使用您的代码:

void AStarMotoVehicle::MoveForward(float Axis)
{
    if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
    { 
        //Angle of direction of camera on Yaw
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
    AddMovementInput(Direction, Axis);

    // could check if World is valid
    UWorld *World = GetWorld();
    

    const float CurrentFOV = FollowCamera->FieldOfView;
    const float InterpSpeed = 2.0f
    FollowCamera->FieldOfView = FMath::FInterpTo(CurrentFOV, 
     140.0f, 
     World->GetTimeSeconds(),
     InterpSpeed);
    }