? 4hc44四虎精品,一级毛片国产a级毛片8
聯(lián)系我們

給我們留言

聯(lián)系我們

地址:福建省晉江市青陽街道洪山路國際工業(yè)設(shè)計(jì)園納金網(wǎng)

郵箱:info@narkii.com

電話:0595-82682267

(周一到周五, 周六周日休息)

當(dāng)前位置:主頁 > 3D教程 > 圖文教程

UE4一個PlayerController控制多個Actor的問題

來源: 52vr | 責(zé)任編輯:傳說的落葉 | 發(fā)布時間: 2019-06-06 08:20 | 瀏覽量:

[UE4]一個PlayerController控制多個Actor的問題

 

UE4中,一個PlayerController同時只能控制一個Actor,如果要實(shí)現(xiàn)RTS游戲中的那種多個Actor同時移動,需要Spawn出來多個Controller(PlayerController或者AIController等,具體看你需求),每個Controller去Possess一個Actor,然后通過控制這多個Controller來實(shí)現(xiàn)移動。

 

如何創(chuàng)建PlayerController,這個帖子講了一種方式:
How do you place APlayerCharacter onto APlayerStart and take control?

https://forums.unrealengine.com/showthread.php?56494-How-do-you-place-APlayerCharacter-onto-APlayerStart-and-take-control

 
  1. In CreateLocalPlayer's case, the call chain you're looking for is:  
  2.   
  3. UGameInstance::CreateLocalPlayer  
  4. ULocalPlayer::SpawnPlayActor  
  5. UWorld::SpawnPlayActor  
  6. AGameMode::PostLogin  
  7. AGameMode::StartNewPlayer  
  8. AGameMode::RestartPlayer  
  9. AGameMode::GetDefaultPawnClassForController  

 相關(guān)代碼:

 
  1. for( int32 a = 0; a < MaxPlayerCount; a++ )  
  2. {  
  3.     ULocalPlayer* localPlayer;  
  4.   
  5.     if( a == 0 )  
  6.     {  
  7.         localPlayer = gameInstance->GetFirstGamePlayer();  
  8.     }  
  9.     else  
  10.     {  
  11.         FString createLocalPlayerError;  
  12.         localPlayer = gameInstance->CreateLocalPlayer( a, createLocalPlayerError, true );  
  13.     }  
  14.   
  15.     FString url;  
  16.     FString spawnPlayActorError;  
  17.     localPlayer->SpawnPlayActor( url, spawnPlayActorError, currentWorld );  
  18.     FURL urlSpawn2;  
  19.     FString spawnError;  
  20.     PostLogin( localPlayer->PlayerController );  
  21.     currentWorld->SpawnPlayActor( localPlayer, ENetRole::ROLE_None, urlSpawn2, localPlayer->GetUniqueNetIdFromCachedControllerId(), spawnError );  
  22.     StartNewPlayer( localPlayer->PlayerController );  
  23.     RestartPlayer( localPlayer->PlayerController );  
  24.   
  25.     /*ABasePlayer* playerActor = ( ABasePlayer* )GetDefaultPawnClassForController( localPlayer->PlayerController ); 
  26.     ABasePlayerController* playerController = ( ABasePlayerController* )localPlayer->PlayerController; 
  27.     playerController->SetUpInput( playerActor, a );*/  
  28. }  

但是上面的RestartPlayer找不到相關(guān)文檔,怎么使用不是很清楚,另外一個替代RestartPlayer的方式:

http://aigo.iteye.com/blog/2285835

 

 

ULocalPlayer

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/ULocalPlayer/index.html

 

UWorld::SpawnPlayActor

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UWorld/SpawnPlayActor/index.html

 

可參考官方的塔防項(xiàng)目:

https://docs.unrealengine.com/latest/INT/Resources/SampleGames/StrategyGame/index.html

 

另外一片關(guān)于UE4中實(shí)現(xiàn)RTS類型游戲移動邏輯的文檔(藍(lán)圖)

RTS Movement and Basic Behaviors on Unreal Engine 4

http://blog.meltinglogic.com/2015/04/unreal-rts-rpg-movement-behaviors/


相關(guān)文章
網(wǎng)友評論

您需要登錄后才可以發(fā)帖 登錄 | 立即注冊

關(guān)閉

全部評論:0條

推薦
熱門