-
게임 조종 카메라게임/UnReal_MakeMyGameStudy 2021. 5. 1. 11:38
게임 조종 카메라
처음에 따라하는 것은
카메라를 활성화시키고, 서로 다른 카메라를 전환하는 법을 보여드리는 튜토리얼입니다.
카메라를 부드럽게 이동시킨다.
예)
카메라1
카메라2
이동 액션
이동 액션을 통해
카메라1 -> 카메라2
카메라2 -> 카메라1
완성 코드
CameraDirector.h
// Fill out your copyright notice in the Description page of Project Settings. // CameraDirector.h #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "CameraDirector.generated.h" UCLASS() class HOWTO_AUTOCAMERA_API ACameraDirector : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties ACameraDirector(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; UPROPERTY(EditAnywhere) AActor* CameraOne; UPROPERTY(EditAnywhere) AActor* CameraTwo; float TimeToNextCameraChange; };
CameraDirector.cpp
// Fill out your copyright notice in the Description page of Project Settings. #include "CameraDirector.h" #include "Kismet/GameplayStatics.h" // Sets default values ACameraDirector::ACameraDirector() { // 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 spawned void ACameraDirector::BeginPlay() { Super::BeginPlay(); } // Called every frame void ACameraDirector::Tick(float DeltaTime) { Super::Tick(DeltaTime); const float TimeBetweenCameraChanges = 2.0f; const float SmoothBlendTime = 0.75f; TimeToNextCameraChange -= DeltaTime; if (TimeToNextCameraChange <= 0.0f) { //이 코드는 3 초마다 기본 플레이어의 뷰를 두 카메라 사이에서 전환시켜 줍니다. TimeToNextCameraChange += TimeBetweenCameraChanges; //로컬 플레이어의 컨트롤을 처리하는 액터를 찾는다. APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0); if (OurPlayerController) { if ((OurPlayerController->GetViewTarget() != CameraOne) && (CameraOne != nullptr)) { //1번 카메라로 즉시 컷해 들어간다. OurPlayerController->SetViewTarget(CameraOne); } else if ((OurPlayerController->GetViewTarget() != CameraTwo) && (CameraTwo != nullptr)) { //2번 카메라로 부드럽게 들어간다. OurPlayerController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime); } } } }
응용
- 게임 매뉴 -> 게임 스타트 -> 카메라 이동 -> 게임 시작!!
- 게임 캐릭터 선택할 때, 할수도 있다.
'게임 > UnReal_MakeMyGameStudy' 카테고리의 다른 글
일인칭 슈팅 C++ 튜토리얼 (0) 2021.05.07 컴포넌트와 콜리전 (0) 2021.05.02 출발!! (0) 2021.05.01