この操作ガイドでは、サードパーソンのサンプルマップで、ゲームプレイ中にプレーヤーの視点に使用される静的 (または固定) のカメラアングルを作成します。その後、キャラクターがボリュームに侵入すると視点を新しいスタティック カメラに移行するトリガー ボリュームを作成します。 このガイドを理解すると、同じプロセスを自分のゲームにも行うことで、プレイヤー用の固定視点を設定できるようになります。
スタティック カメラ アクタを作成する
Begin by creating a New > Games > Third Person > C++ project named StaticCameras.
Launch the C++ Class Wizard, enable the checkbox for Show All Classes, then type CameraActor within the search field to select and create your new Camera Actor class named ExampleCameraActor.
From the C++ Class panel, right click on your ExampleCamera and from the dropdown C++ Class actions menu select Create a Blueprint class based on ExampleCameraActor. Then drag an instance of BP_ExampleCameraActor into the level.
レベル設定
プレイヤーのカメラとスタティック カメラ アクタの間の視点の移動を示すために、シーンを設定する必要があります。 これは、サードパーソン テンプレート レベルからスタティック メッシュジオメトリの一部を変更することで作成できます。
[ワールド アウトライナ] パネルに移動して、「ArenaGeometry」>「Arena」フォルダから床 と 4 つの 壁スタティック メッシュ アクタを選択します。
上の画像の例では、4 つの壁スタティックメッシュ アクタは、Wall6、Wall7、Wall8、および Wall9 としてリストされています。
Alt キーを押しながら、トランスフォーム ギズモをクリックしてドラッグし、床と壁のセットアップを複製します。
これにより、2 つ目の床と、4 つの壁のスタティック メッシュ アクタが作成されます。
上の画像の例では、複製された床には Floor2 というラベルが付いており、複製された壁には、Wall10、Wall11、Wall12、Wall13という名前が付けられています。
新しく複製されたスタティック メッシュを下のレイアウトのように移動します。新しい部屋は最初のメッシュのみ複製し、コンテンツは何もありません。
[ワールド アウトライナ] から、2 つの部屋を接続する 2 枚の壁を選択し、それらの [Scale (スケール)] の [X] を「14」に設定します。
上の画像の例では、これら 2 つの壁に、Wall9とWall12というラベルが付いています。
接続する壁を両方選択してから、 トランスフォーム ギズモを使用してそれらを移動します。それにより、以下の GIF に示すように、部屋にある隙間にパーティションを作成します。
上の画像の例では、これら 2 つの壁に、Wall9とWall10というラベルが付いています。
完成したレベル設定は、下の画像のようになります。壁の開口部によって最初の部屋と二つ目の部屋がつながっています。
カメラのパースペクティブを設定する
レベルの設定が完了したところで、、トリガー ボリュームと重なったときにプレイヤーの視点となる BP_ExampleCameraActor レベルに配置することができます。これにより、視点をより良く把握できます。 [ビューポート] をカメラ アクタにロックして パイロット モードに入ると、カメラ視点から一人称視点に切り替えられます。
レベルでカメラを選択した状態でカメラを右クリックし、コンテキスト メニューから[パイロット カメラ アクタ] を選択します。
これで、マウスの左ボタンまたは右ボタンを押したまま、WASD キーを使用することで、ビューポート内を移動できるようになります。 これで、レベル内を移動している間、カメラの位置は動きに合わせて移動するため、ゲームプレイ中にカメラがとる視点を把握できます。
カメラのロックを解除するには、[ロック解除] ボタンをクリックします。
ロックを解除すると、カメラは配置された場所に残ります。 また、[Unlock] ボタンの横にあるアイコンは、ゲーム内のカメラ ビューとレベルエディタ ビューのどちらを表示するかを切り替えることができます。
下の gif のように、二つ目の部屋を見下ろす位置にカメラを移動します。
完成したカメラシーンのセットアップは、下の画像のようになります。スタティック カメラが新しい部屋を見下ろし、元のカメラがサードパーソン アクタを追従します。
オーバーラップ トリガー アクタを作成する
この例では、トリガー アクタは、プレイヤーのカメラ ビューポイントとスタティック カメラ ビューポイントの間の遷移を管理しています。プレイヤーがボックス コンポーネントのボリュームの境界と重なると、視点間の切り替えを示す遷移ブレンドが発生します。
Using the C++ Class Wizard, create a new Actor class named BlendTriggerVolume.
Navigate to your
BlendTriggerVolume.hfile, and declare the following code in your class definition.C++protected: //Collision Bounds of the Actor Volume UPROPERTY(EditAnywhere, BlueprintReadWrite) class UBoxComponent* OverlapVolume; //Camera Actor which the Actor Volume blends to UPROPERTY(EditAnywhere, BlueprintReadWrite) TSubclassOf<ACameraActor> CameraToFind;Next, navigate to your
BlendTriggerVolume.cppfile to set up your constructor and box component overlap methods. Declare the following include class libraries.C++`#include "Components/BoxComponent.h"` `#include "StaticCamerasCharacter.h"` `#include "Camera/CameraActor.h"` `#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"`In the constructor ABlendTriggerVolume::ABlendTriggerVolume, declare the following code.
C++ABlendTriggerVolume::ABlendTriggerVolume() { //Create box component default components OverlapVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("CameraProximityVolume")); //Set the box component attachment to the root component. OverlapVolume->SetupAttachment(RootComponent); }Next, implement your
NotifyActorBeginOverlapandNotifyActorEndOverlapclass methods:C++void ABlendTriggerVolume::NotifyActorBeginOverlap(AActor* OtherActor){ //Cast check to see if overlapped Actor is Third Person Player Character if (AStaticCamerasCharacter* PlayerCharacterCheck = Cast<AStaticCamerasCharacter>(OtherActor)) { //Cast to Player Character's PlayerController if (APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController())) {Compile your code.
Finished Code
BlendTriggerVolume.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BlendTriggerVolume.generated.h"
UCLASS()
class STATICCAMERAS_API ABlendTriggerVolume : public AActor
{
GENERATED_BODY()
BlendTriggerVolume.cpp
#include "BlendTriggerVolume.h"
#include "Components/BoxComponent.h"
#include "StaticCamerasCharacter.h"
#include "Camera/CameraActor.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
// Sets default values
ABlendTriggerVolume::ABlendTriggerVolume()
{
Setting up the Overlap Trigger Actor
Now that you have created your overlap Actor, you will need to place it into the level and set up its bounds.
Begin by navigating to your C++ Classes folder, right-click on your BlendTriggerVolume class, select Create Blueprint Class based on BlendTriggerVolume, then name your Blueprint Actor BP_BlendTriggerVolume.
From the class defaults, navigate to Camera To Find in the Details panel, open the drop down menu, then select BP_ExampleCameraActor.
Optionally, you can change the default blend time for this Blueprint without having to go back into the source code, or affecting other Blueprints with the same inherited parent class.
Compile and Save.
From the Content Browser, drag an instance of BP_BlendTriggerVolume into the level.
Move the BP_BlendTriggerVolume into the room with your BP_ExampleCameraActor, and from the Details panel select the box component. Navigate to the Shape category and modify the Box Extent X, Y, and Z values so the volume will fit your room.
From the Main Editor View, click the Play button to play in the Editor.
最終結果
ゲームが始まると、プレイヤーは WASD 使用してキャラクターを動かします。 キャラクターが BP_BlendTriggerVolume に入ると、カメラ ビューは先ほど作成してレベルに配置したカメラ アクタに割り当てられ、ビューがプレイヤーが制御するキャラクターの頭上に切り替わります。
この際、ビューがワイドスクリーンになっていることに気がついた方もいると思います。これを無効にするには、カメラアクタの [詳細] パネル内の [アスペクト比を制約] オプションをオフにします。