在此操作指南教程中,你将创建一个静态(或固定)摄像机角度,用于玩家在第三人称示例地图中Gameplay时的玩家角度,然后你将创建一个在你的角色与体积重叠时将你的视点过渡到新静态摄像机的触发器体积。 完成此教程时,你可以将此处使用的流程应用到你自己的游戏中,为玩家设置固定角度。
创建静态摄像机Actor
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.
关卡设置
为了展示玩家摄像机和静态摄像机actor之间的视角过度,你需要设置场景。 要完成此目标,你需要从第三人称模板关卡中修改某些静态网格体几何体。
首先找到世界大纲视图面板,转到ArenaGeometry > Arena文件夹,按住Shift选择地板(Floor)和4个墙体(Wall)静态网格体Actor。
在上图中,四个墙体静态网格体Actor分别是Wall6、Wall7、Wall8和Wall9。
按住Alt并点击变换(Transform)小工具然后拖动,创建重复的地板和墙体设置。
这将创建第二个地板和其他四个墙体静态网格体Actor。
在上图中,重复的地板是Floor2,重复的墙体是Wall10、Wall11、Wall12和Wall13。
移动新复制的静态网格体以组装下面的布局,从原始房间复制而来的新房间将出现,但没有任何内容。
在世界大纲视图中,选择连接两个房间的两面墙,然后将其X轴比例(X Scale)的值设置为14。
在上图中,这两面墙是Wall9和Wall12。
选择这两面相连的墙体,然后使用变换(Transform)小工具移动它们,使它们成为房间之间的分区,并具有如下所示的间隔。
在上图中,这两面墙是Wall9和Wall10
已完成的关卡设置看起来应该类似于下图,第二个房间通过墙上的一个开口连接到第一个房间。
摄像机视角设置
现在你已经完成了关卡设置,可以将 BP_ExampleCameraActor放置在关卡中了,从而更好地了解在玩家在与触发器体积重叠时获得的视野。 将视口(Viewport)锁定到摄像机Actor并进入导航(Pilot)模式,即可从摄像机的角度获取第一人称视角。
在关卡中选择摄像机之后,右键点击摄像机,然后从上下文菜单中选择导航CameraActor(Pilot CameraActor)。
你现在可以在按住鼠标左键或鼠标右键的时候使用WASD键来在视口中移动。 在关卡中飞翔时,摄像机的位置将随着你的移动而移动,从而让你了解摄像机在Gameplay期间获得的角度。
要解锁摄像机,点击解锁按钮即可。
摄像机将留在解锁时的位置。 解锁按钮旁边的图标可以用于在显示游戏内摄像机视图和关卡编辑器视图之间进行切换。
将摄像机导航到在第二个房间上俯视的位置,类似于下面的gif。
已完成的摄像机场景设置看起来应该类似于下图,静态摄像机俯视新房间,而原始摄像机跟随第三人称Actor。
创建重叠触发器Actor
在这个示例中,触发器Actor充当了玩家摄像机视角和静态摄像机视角之间的过渡管理器,一旦玩家碰到它的碰撞盒,两种视角就会切换。
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重叠时,摄像机视图会被指定到你创建并放置到关卡中的摄像机Actor(Camera Actor)上,同时视图将被切换到玩家控制的角色的俯拍镜头。
你可能还会注意到,视图采用了宽屏模式;要禁用此设置,请转到细节(Details)面板,为摄像机Actor取消勾选约束高宽比(Constrain Aspect Ratio)选项。