我目前正在做一个项目,我的所有球员使用不同的相机。
我首先想到的是使用UCameraComponent,但是每个摄像头都必须绕着某个点旋转,而不是随着棋子的移动而移动。
因此,我决定在我的棋子的BeginPlay()中生成一个相机演员。
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
if (!hasCamera) { // Camera not set yet
FVector vectpos; // Target position of the camera
vectpos.X = -1130;
vectpos.Y = 10;
vectpos.Z = 565;
FRotator rotation;
rotation.Pitch = -22;
rotation.Yaw = 0;
rotation.Roll = 0;
APlayerController* controller = Cast<APlayerController>(GetController());
if (controller == NULL) // When I'm on client, the GetController() return NULL.
{
// Trying to find the controller of my client
for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
{
controller = *Iterator;
//On client, there is only 1 controller according to the documentation.
}
}
if (controller != NULL)
{
controller->SetViewTarget(Camera); // Set the view with the new camera
}
SetCamera(true); // Call and RPC Function to update the hasCamera variable
}
}这是为第一名球员工作,在那之后,它取决于。有时,第二个玩家得到的相机工作良好,但有时,他是通过错误的相机和相机变量是不同的,他正在寻找。有时,当一个新玩家加入游戏时,它会让第一个/第二个玩家通过错误的摄像机观看。
这里是GameInstance蓝图,我们用它来连接客户端和服务器(创建游戏的第一个客户端)

如果有人能找到为什么相机不能像预期的那样工作,那就太好了!提前谢谢你们的帮助。
发布于 2017-04-20 05:38:49
显然,你选择了错误的方式。
在UE4中,'ACharacter‘(准确地说是APawn)是世界上的一个字符表示,所以每个玩家都有一个字符表示。因此,把你的相机代码放在里面是很奇怪的。
你应该自己做控制器(前)。(“AMyPlayerController”)和控制摄像头。很明显,只适合本地球员。
https://stackoverflow.com/questions/43484933
复制相似问题