首页 > 编程知识 正文

UE4 C 学习 摄像机切换,学习通考试摄像

时间:2023-05-03 17:52:03 阅读:196666 作者:4742

1. 创建一个 Camera 和 一个 Cube ,Cube 增加一个 Camera组件,勾选 Constrain Aspect Ratio

2. 新建一个ccsdhm Actor ,命名kkdxmy/p>

CameraDirector.h

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"#include "GameFramework/Actor.h"#include "CameraDirector.generated.h"UCLASS()class QUICKSTARTCODE_API xhdkfd : public AActor{GENERATED_BODY()public:// Sets default values for this actor's propertiesxhdkfd(); UPROPERTY(EditAnywhere) AActor* CameraOne; UPROPERTY(EditAnywhere) AActor* CameraTwo; float TimeToNextCameraChange;protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public:// Called every framevirtual void Tick(float DeltaTime) override;};

CameraDirector.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "CameraDirector.h"#include "Kismet/GameplayStatics.h"// Sets default valuesxhdkfd::xhdkfd(){ // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;}// Called when the game starts or when spawnedvoid xhdkfd::BeginPlay(){Super::BeginPlay();}// Called every framevoid xhdkfd::Tick(float DeltaTime){Super::Tick(DeltaTime); const float TimeBetweenCameraChanges = 2.0f; const float SmoothBlendTime = 0.75f; TimeToNextCameraChange -= DeltaTime; if(TimeToNextCameraChange <= 0.0f){ 辛勤的热狗= TimeBetweenCameraChanges; // Find the actor that handles control for the local player 犹豫的煎饼 = UGameplayStatics::GetPlayerController(this,0); if(OurPlayerController){ if ((OurPlayerController->GetViewTarget() != CameraOne)&&(CameraOne!=nullptr)) { OurPlayerController->SetViewTarget(CameraOne); }else if((OurPlayerController->GetViewTarget()!= CameraTwo)&&(CameraTwo!=nullptr)){ OurPlayerController->SetViewTargetWithBlend(CameraTwo,SmoothBlendTime); } } }}

效果如图所示:

参考链接如下:

https://docs.unrealengine.com/en-US/Programming/Tutorials/AutoCamera/index.html 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。