? ,,

亚洲午夜精品视频_国产黄大片_网站av_99亚洲伊人久久精品影院红桃_91av入口_永久免费av片在线观看全网站

聯系我們

給我們留言

聯系我們

地址:福建省晉江市青陽街道洪山路國際工業設計園納金網

郵箱:info@narkii.com

電話:0595-82682267

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

當前位置:主頁 > 3D教程 > 圖文教程

UE4 網游中角色Pawn的移動位置同步以及RTS多角色同

來源: 52vr | 責任編輯:傳說的落葉 | 發布時間: 2019-06-06 08:23 | 瀏覽量:

[UE4]網游中角色Pawn的移動位置同步以及RTS多角色同時移動的解決方案

 

下面方案的思路是:
每個Actor,為其定義一個代理(ActorProxy),真實的Actor放在服務端,代理ActorProxy放在客戶端,移動Actor時,實際是移動服務端上的Actor,然后對客戶端ActorProxy的位置進行同步。

攝像機綁定的是ActorProxy,服務端的真實Actor不用攝像機;而AIController實際控制的是服務端Actor,客戶端其實沒有AIController。

另外,下面例子的同步機制使用的UE4自身集成的Replication(也就是常用的UFUNCTION(Server, Reliable, WithValidation)),這個是非常耗費帶寬的,因為是定時且頻繁的同步數據。這個如果是做局域網服務端還可以,但是如果是大型高負載服務端,建議自己實現同步機制。另外,v4.4開始,shipping編譯出來的版本會自動刪掉UE4的server模式。原因肯定是官方也不希望這個方便測試的同步機制被開發者應用到生產環境中。所以下面例子中,參考下它的思路即可,具體的同步處理的細節問題可以忽略。

 

RTS游戲中多角色同時移動的方案:

為在每個自定義Pawn類定義個AIController,群體移動時,遍歷所有Pawn,依次調用各自的AIController->MoveToLocation。

 

另外注意點:AIController->MoveToLocation無法像UNavigationSystem->SimpleMoveToLocation()那樣可以主動繞開障礙物,一般建議在服務端通過UNavigationSystem獲取移動路徑的數據,然后將這些數據與客戶端同步。

可參考:
Creating a Movement Component for an RTS in UE4 
http://www.gamedev.net/page/resources/_/technical/game-programming/creating-a-movement-component-for-an-rts-in-ue4-r4019

 

=============================================================================

=============================================================================

下面文章有點不足的問題是:服務端是通過AIController->MoveToLocation來尋路的,如果對于一個有障礙物的地圖來啊,移動的時候會出現停滯。另外文章建議說服務端不要用UNavigationSystem>SimpleMoveToLocation,這個可能是誤解,服務端是可以使用的。
 

正文:

[UE4] Getting Multiplayer Player Pawn AI Navigation to work (C++)

http://droneah.com/content/ue4-getting-multiplayer-player-pawn-ai-navigation-work-c

 

Unreal Engine is an awesome piece of technology making it easy to do almost anything you might want.

 

When using the Top Down view however, there is a hurdle to get over when trying to get multiplayer to work. This is a C++ project solution to this problem based on a BluePrints solution.

 

The basic problem stems from the fact that

 

"SimpleMoveToLocation was never intended to be used in a network environment. It's simple after all ;) Currently there's no dedicated engine way of making player pawn follow a path. " (from the same page)

 

To be able to get a working version of SimpleMoveToLocation, we need to do the following:

 

Create a proxy player class (BP_WarriorProxy is BP solution)

Set the proxy class as the default player controller class

Move the camera to the proxy (Since the actual player class is on the server, we can't put a camera on it to display on the client)

The BP solution talks about four classes - our counterparts are as follows:

 

BP_WarriorProxy: ADemoPlayerProxy

BP_WarriorController: ADemoPlayerController (Auto-created when creating a c++ top down project)

BP_Warrior: ADemoCharacter (Auto-created when creating a C++ top down project)

BP_WarriorAI: AAIController - we have no reason to subclass it.

So, from a standard c++ top down project, the only class we need to add is the ADemoPlayerProxy - so go ahead and do that first.

 

The first thing we'll do is rewire the ADemoGameMode class to initialise the proxy class instead of the default MyCharacter Blueprint.

 
  1. ADemoGameMode::ADemoGameMode(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)   
  2. {   
  3.     // use our custom PlayerController class   
  4.     PlayerControllerClass = ADemoPlayerController::StaticClass();   
  5.    
  6.     // set default pawn class to our Blueprinted character   
  7.     /* static ConstructorHelpers::FClassFinder<apawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/MyCharacter"));  
  8.     if (PlayerPawnBPClass.Class != NULL)  
  9.     {  
  10.         DefaultPawnClass = PlayerPawnBPClass.Class;  
  11.     }*/   
  12.    
  13.     DefaultPawnClass = ADemoPlayerProxy::StaticClass();   
  14. }   

 

Our Player Proxy class declaration

 
  1. /* This class will work as a proxy on the client - tracking the movements of the  
  2.  * real Character on the server side and sending back controls. */   
  3. UCLASS() class Demo_API ADemoPlayerProxy : public APawn   
  4. {   
  5.     GENERATED_UCLASS_BODY()   
  6.     /** Top down camera */   
  7.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera) TSubobjectPtr<class ucameracomponent> TopDownCameraComponent;   
  8.    
  9.     /** Camera boom positioning the camera above the character */   
  10.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera) TSubobjectPtr<class uspringarmcomponent> CameraBoom;   
  11.    
  12.     // Needed so we can pick up the class in the constructor and spawn it elsewhere   
  13.     TSubclassOf<aactor> CharacterClass;   
  14.    
  15.     // Pointer to the actual character. We replicate it so we know its location for the camera on the client   
  16.     UPROPERTY(Replicated) ADemoCharacter* Character;   
  17.    
  18.     // The AI Controller we will use to auto-navigate the player   
  19.     AAIController* PlayerAI;   
  20.    
  21.     // We spawn the real player character and other such elements here   
  22.     virtual void BeginPlay() override;   
  23.    
  24.     // Use do keep this actor in sync with the real one   
  25.     void Tick(float DeltaTime);   
  26.    
  27.     // Used by the controller to get moving to work   
  28.     void MoveToLocation(const FVector& vector);   
  29. };   

 

and the definition:

 
  1. #include "Demo.h"  
  2. #include "DemoCharacter.h"  
  3. #include "AIController.h"  
  4. #include "DemoPlayerProxy.h"  
  5. #include "UnrealNetwork.h"  
  6.    
  7.    
  8. ADemoPlayerProxy::ADemoPlayerProxy(const class FPostConstructInitializeProperties& PCIP)  
  9. : Super(PCIP)  
  10. {  
  11.     // Don't rotate character to camera direction  
  12.     bUseControllerRotationPitch = false;  
  13.     bUseControllerRotationYaw = false;  
  14.     bUseControllerRotationRoll = false;  
  15.    
  16.     // It seems that without a RootComponent, we can't place the Actual Character easily  
  17.     TSubobjectPtr<UCapsuleComponent> TouchCapsule = PCIP.CreateDefaultSubobject<ucapsulecomponent>(this, TEXT("dummy"));  
  18.     TouchCapsule->InitCapsuleSize(1.0f, 1.0f);  
  19.     TouchCapsule->SetCollisionEnabled(ECollisionEnabled::NoCollision);  
  20.     TouchCapsule->SetCollisionResponseToAllChannels(ECR_Ignore);  
  21.     RootComponent = TouchCapsule;  
  22.    
  23.     // Create a camera boom...  
  24.     CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));  
  25.     CameraBoom->AttachTo(RootComponent);  
  26.     CameraBoom->bAbsoluteRotation = true// Don't want arm to rotate when character does  
  27.     CameraBoom->TargetArmLength = 800.f;  
  28.     CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);  
  29.     CameraBoom->bDoCollisionTest = false// Don't want to pull camera in when it collides with level  
  30.    
  31.     // Create a camera...  
  32.     TopDownCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("TopDownCamera"));  
  33.     TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);  
  34.     TopDownCameraComponent->bUseControllerViewRotation = false// Camera does not rotate relative to arm  
  35.    
  36.     if (Role == ROLE_Authority)  
  37.     {  
  38.         static ConstructorHelpers::FObjectFinder<UClass> PlayerPawnBPClass(TEXT("/Game/Blueprints/MyCharacter.MyCharacter_C"));  
  39.         CharacterClass = PlayerPawnBPClass.Object;  
  40.     }  
  41.    
  42. }  
  43.    
  44. void ADemoPlayerProxy::BeginPlay()  
  45. {  
  46.     Super::BeginPlay();  
  47.     if (Role == ROLE_Authority)  
  48.     {  
  49.         // Get current location of the Player Proxy  
  50.         FVector Location =  GetActorLocation();  
  51.         FRotator Rotation = GetActorRotation();  
  52.    
  53.         FActorSpawnParameters SpawnParams;  
  54.         SpawnParams.Owner = this;  
  55.         SpawnParams.Instigator = Instigator;  
  56.         SpawnParams.bNoCollisionFail = true;  
  57.    
  58.         // Spawn the actual player character at the same location as the Proxy  
  59.         Character = Cast<ADemoCharacter>(GetWorld()->SpawnActor(CharacterClass, &Location, &Rotation, SpawnParams));  
  60.    
  61.         // We use the PlayerAI to control the Player Character for Navigation  
  62.         PlayerAI = GetWorld()->SpawnActor<AAIController>(GetActorLocation(), GetActorRotation());  
  63.         PlayerAI->Possess(Character);  
  64.     }  
  65.    
  66. }  
  67.    
  68. void ADemoPlayerProxy::Tick(float DeltaTime)  
  69. {  
  70.    
  71.     Super::Tick(DeltaTime);  
  72.     if (Character)  
  73.     {  
  74.         // Keep the Proxy in sync with the real character  
  75.         FTransform CharTransform = Character->GetTransform();  
  76.         FTransform MyTransform = GetTransform();  
  77.    
  78.         FTransform Transform;  
  79.         Transform.LerpTranslationScale3D(CharTransform, MyTransform, ScalarRegister(0.5f));  
  80.    
  81.         SetActorTransform(Transform);  
  82.    
  83. <li micxptag"="" style="overflow-wrap: break-word; margin: 0px 0px 0px 38px; padding: 0px; font-size: 1em;">虛幻4,ue4,虛幻4入門,虛幻4基礎,虛幻4高級


相關文章
網友評論

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

關閉

全部評論:0條

推薦
熱門
主站蜘蛛池模板: 国产av无码日韩av无码网站 | 夜夜爽一区二区三区精品 | 黄色一级片免费在线观看 | 一级特黄a免费大片 | 久久久久国色av免费观看性色 | 夜夜揉揉日日人人 | 亚洲精品www久久久久久 | 亚洲国产成人最新精品资源 | 麻豆国产在线精品国偷产拍 | 久久青草18免费观看网站 | 国产精品免费大片 | 色妞女女女女女bbbbb1 | 无码av天堂一区二区三区 | 熟女人妻少妇精品视频 | 秋霞一级成人欧美理论 | 伊人精品综合 | 99久久久精品免费观看国产 | 亚洲av人人夜夜澡人人 | 人妻少妇精品专区性色av | 狠狠色噜噜狠狠狠777米奇小说 | 久久精品国产亚洲av麻豆蜜芽 | 欧美成人黑人视频免费观看 | 草草网站影院白丝内射 | 成人美女免费网站视频 | 国产高清一级毛片在线人 | 国产黄色免费网站 | 求欧美精品网址 | 在线看片亚洲 | 日本人妻人人人澡人人爽 | 狠狠爱俺也去去就色 | 日韩国产精品欧美一区二区 | 成人网站免费大全日韩国产 | 亚洲一区二区观看播放 | 国产一级毛片夜一级毛片 | 久久er热在这里只有精品85 | 精品成人免费视频 | 亚洲精品一区三区三区在线观看 | 亚洲综合性图 | 天堂一区二区三区在线观看 | 4hu影院最新地址www | 天天摸夜夜摸夜夜狠狠摸 |