【问题标题】:Changing FOV(Field of view) while moving forward前进时改变 FOV(视野)
【发布时间】:2020-10-27 14:39:34
【问题描述】:

我有情况。我想在前进的同时顺利地改变 FOV。在父类的相机设置中,我设置了默认值:

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 顺利完成。 你能帮我吗?

【问题讨论】:

    标签: c++ unreal-engine4 unreal-development-kit


    【解决方案1】:

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

    每次调用“MoveForward”,fov 都会增加到 140。 要减慢/加快过渡,请减小/增加 InterpSpeed 值

    使用您的代码:

    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);
        }
    

    【讨论】:

    • 感谢您的回答。但是当我启动它并尝试前进之后。应用程序崩溃。我怀疑这是因为我没有正确获取 GetTimeSeconds。我创建了 Uworld * World class(在我的车内),它似乎不正确,对吧?
    • 是的,在 Actor 中获取 World :docs.unrealengine.com/en-US/API/Runtime/Engine/GameFramework/… 我以为你知道如何获取 World,这就是我直接编写 World 的原因,我会更新我的代码。 @FedorPetrenko 完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2018-10-17
    • 2013-10-25
    • 2017-10-12
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多