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
- In CreateLocalPlayer's case, the call chain you're looking for is:
- UGameInstance::CreateLocalPlayer
- ULocalPlayer::SpawnPlayActor
- UWorld::SpawnPlayActor
- AGameMode::PostLogin
- AGameMode::StartNewPlayer
- AGameMode::RestartPlayer
- AGameMode::GetDefaultPawnClassForController
相關(guān)代碼:
- for( int32 a = 0; a < MaxPlayerCount; a++ )
- {
- ULocalPlayer* localPlayer;
- if( a == 0 )
- {
- localPlayer = gameInstance->GetFirstGamePlayer();
- }
- else
- {
- FString createLocalPlayerError;
- localPlayer = gameInstance->CreateLocalPlayer( a, createLocalPlayerError, true );
- }
- FString url;
- FString spawnPlayActorError;
- localPlayer->SpawnPlayActor( url, spawnPlayActorError, currentWorld );
- FURL urlSpawn2;
- FString spawnError;
- PostLogin( localPlayer->PlayerController );
- currentWorld->SpawnPlayActor( localPlayer, ENetRole::ROLE_None, urlSpawn2, localPlayer->GetUniqueNetIdFromCachedControllerId(), spawnError );
- StartNewPlayer( localPlayer->PlayerController );
- RestartPlayer( localPlayer->PlayerController );
- /*ABasePlayer* playerActor = ( ABasePlayer* )GetDefaultPawnClassForController( localPlayer->PlayerController );
- ABasePlayerController* playerController = ( ABasePlayerController* )localPlayer->PlayerController;
- playerController->SetUpInput( playerActor, a );*/
- }
但是上面的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/
-
分享到:
您需要登錄后才可以發(fā)帖 登錄 | 立即注冊
- 用戶名:
- 密 碼:
- 驗(yàn)證碼: 看不清? 點(diǎn)擊更換
- 忘記密碼?
全部評論:0條