首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >虚拟引擎4联网中的摄像机问题

虚拟引擎4联网中的摄像机问题
EN

Stack Overflow用户
提问于 2017-04-19 01:49:36
回答 1查看 3.2K关注 0票数 0

我目前正在做一个项目,我的所有球员使用不同的相机。

我首先想到的是使用UCameraComponent,但是每个摄像头都必须绕着某个点旋转,而不是随着棋子的移动而移动。

因此,我决定在我的棋子的BeginPlay()中生成一个相机演员。

代码语言:javascript
复制
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蓝图,我们用它来连接客户端和服务器(创建游戏的第一个客户端)

如果有人能找到为什么相机不能像预期的那样工作,那就太好了!提前谢谢你们的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-20 05:38:49

显然,你选择了错误的方式。

在UE4中,'ACharacter‘(准确地说是APawn)是世界上的一个字符表示,所以每个玩家都有一个字符表示。因此,把你的相机代码放在里面是很奇怪的。

你应该自己做控制器(前)。(“AMyPlayerController”)和控制摄像头。很明显,只适合本地球员。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43484933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档