摄像机应该是使用最普遍的组件了
获取摄像机,摄像机切换
-
新建C++类(以CameraActor为父类) -
将摄像机在地图中放置 -
头文件声明 virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UBoxComponent* OverlapVolume;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<ACameraActor> CameraToFind;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float CameraBlendTime;
virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;
virtual void NotifyActorEndOverlap(AActor* OtherActor) override;
-
实现 void ABlendTriggerVolume::NotifyActorBeginOverlap(AActor* OtherActor)
{
Super::NotifyActorBeginOverlap(OtherActor);
if(AStaticCameraCharacter* PlayerCharacterCheck = Cast<AStaticCameraCharacter>(OtherActor))
{
if(APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController()))
{
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), CameraToFind, FoundActors);
PlayerCharacterController->SetViewTargetWithBlend(FoundActors[0], CameraBlendTime,
EViewTargetBlendFunction::VTBlend_Linear);
}
}
}
void ABlendTriggerVolume::NotifyActorEndOverlap(AActor* OtherActor)
{
Super::NotifyActorEndOverlap(OtherActor);
if (AStaticCameraCharacter* PlayerCharacterCheck = Cast<AStaticCameraCharacter>(OtherActor))
{
if(APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController()))
{
PlayerCharacterController->SetViewTargetWithBlend(PlayerCharacterController->GetPawn(), CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);
}
}
}
-
之后我们基于摄像机类创建蓝图类,并设置相关内容 在蓝图细节中找到如下,并设置
|