현재 모든 플레이어가 다른 카메라를 사용하는 프로젝트를 진행 중입니다.언리얼 엔진 4와 네트워크 연결시 카메라 문제
나는 처음에 UCameraComponent를 사용하여 생각했지만, 각 카메라는 폰의 움직임으로 움직이지 않고 특정 지점을 돌아야했습니다.
그래서 내 폰의 BeginPlay()에 Camera Actor를 스폰하기로 결정했습니다.
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
}
}
이것은 첫 번째 플레이어에서 작동하며 이후에는 다릅니다. 때로는 두 번째 플레이어가 제대로 작동하는 카메라를 얻는 경우도 있지만 때로는 잘못된 카메라를 통해보고 있으며 Camera 변수는 찾고있는 것과 다릅니다. 때로는 새 플레이어가 게임에 참여할 때 첫 번째 플레이어가됩니다/두 번째 플레이어가 잘못된 카메라를보고 있습니다.
여기 우리는 고객 bewteen의 LAN 연결 및 서버 (게임을 만들 수있는 첫 번째 클라이언트)를 만드는 데 사용하는 GameInstance 청사진이다
누군가가 예상대로 카메라가 작동하지 않는 이유를 찾아 낼 수있는 경우에 , 그것은 아주 좋을 것입니다! 도와 주셔서 미리 감사드립니다.
네트워크 서버에는 모든 플레이어 컨트롤러가 있으며, 항상 마지막 플레이어를 가져옵니다. 'UEngine :: GetFirstLocalPlayerController'를 사용하려고 시도하십시오. –
답장을 보내 주셔서 감사합니다.이 작업을 시도했지만 서버에서 작동하지만 두 번째 플레이어와 연결하면 서버가 카메라를 잃어 버립니다. 세 번째 플레이어와 연결하면 모두가 카메라를 잃어 버립니다. BeginPlay가 클라이언트와 서버에서 호출되고 서버가 Camera 변수의 값을 잘못 변경했기 때문일 수 있습니까? 현재 카메라를 통해 볼 수있는 방법이 있습니까? – Matriac
모든 플레이어에 대해 서버에서'BeginPlay'가 호출됩니다. 처음에는'APawn'은'GetController' 함수를 가지고 있습니다. 따라서 어딘가에서 찾을 필요가 없습니다. 둘째,'AController'는'IsLocalController'를 가지고 있으므로 로컬 또는 네트워크 플레이어 컨트롤러인지 알 수 있습니다. –