Setup Post-mission Camera

编辑BP_GameMode

新建Actor命名为BP_SpectatingViewpoint

添加摄像机

将摄像机调整到合适的位置,右键选择

调整到合适的位置,点击这个按钮,退出驾驶模式

摄像机已经移动到合适的位置

 回到BP_GameMode,在这一位置上设置了摄像机

给镜头移动添加慢动作,只需要修改参数

将上述逻辑连接断开,将用代码实现

在FPSGameMode头文件中新建变量

protected:
    UPROPERTY(EditDefaultsOnly,Category="Spectating")
    TSubclassOf<AActor> SpectatingViewpointClass;  

在FPSGameMode的Cpp文件中修改CompleteMission函数

void AFPSGameMode::CompleteMission(APawn* InstigatorPawn)
{
    if (InstigatorPawn)
    {
        InstigatorPawn->DisableInput(nullptr);
        if (SpectatingViewpointClass)
        {
            TArray<AActor*> ReturnedActors;
            UGameplayStatics::GetAllActorsOfClass(this, SpectatingViewpointClass, ReturnedActors);
            //找到任何有效actor后,更改目标视角
            if (ReturnedActors.Num() > 0)
            {
                AActor* NewViewTarget = ReturnedActors[0];
                APlayerController* PC = Cast<APlayerController>(InstigatorPawn->GetController());
                if (PC)
                {
                    PC->SetViewTargetWithBlend(NewViewTarget, 0.5f, EViewTargetBlendFunction::VTBlend_Cubic);
                }
            }
        }
        else
        {
            UE_LOG(LogTemp, Warning, TEXT("SpectatingViewpointClass is nullptr"));
        }
    }
    OnMissionComplete(InstigatorPawn);
}

将之前建的变量赋值

猜你喜欢

转载自www.cnblogs.com/suomeimei/p/10356115.html