[UE] Multiplayer 1: Listen Server Testing, LAN Connection
프로젝트를 패키지하여 LAN으로 연결되는 기본 게임을 구현해본다. 컴퓨터의 IP 주소를 활용하여 제3자 컴퓨터가 접속하여 네트워크에 접속하여 참여한다.
목차
Multiplayer 1: Listen Server Testing
ThirdPersonCharacter
Event Graph
※ 자기 컴퓨터의 IP 주소 찾는법
Command Prompt에 ipconfig 입력 후 엔터
- IPv4 주소가 자기 컴퓨터의 IP 주소이다.
프로젝트 패키지 하기 (Package Project)
제3자 컴퓨터에서 LANTesting.exe 파일을 열어 접속한다.
C++ 코드로 구현하기
LANTestCharacter
LANTestCharacter.h
더보기
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "LANTestCharacter.generated.h"
UCLASS(config=Game)
class ALANTestCharacter : public ACharacter
{
GENERATED_BODY()
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
public:
ALANTestCharacter();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Input)
float TurnRateGamepad;
protected:
void MoveForward(float Value);
void MoveRight(float Value);
void TurnAtRate(float Rate);
void LookUpAtRate(float Rate);
void TouchStarted(ETouchIndex::Type FingerIndex, FVector Location);
void TouchStopped(ETouchIndex::Type FingerIndex, FVector Location);
protected:
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
public:
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
UFUNCTION(BlueprintCallable)
void OpenLobby();
UFUNCTION(BlueprintCallable)
void CallOpenLevel(const FString& Address);
UFUNCTION(BlueprintCallable)
void CallClientTravel(const FString& Address);
};
LANTestCharacter.cpp
더보기
#include "LANTestCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h"
ALANTestCharacter::ALANTestCharacter()
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// set our turn rate for input
TurnRateGamepad = 50.f;
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate
// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
// instead of recompiling to adjust them
GetCharacterMovement()->JumpZVelocity = 700.f;
GetCharacterMovement()->AirControl = 0.35f;
GetCharacterMovement()->MaxWalkSpeed = 500.f;
GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
// Create a camera boom (pulls in towards the player if there is a collision)
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
// Create a follow camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
}
//////////////////////////////////////////////////////////////////////////
// Input
void ALANTestCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
// Set up gameplay key bindings
check(PlayerInputComponent);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
PlayerInputComponent->BindAxis("Move Forward / Backward", this, &ALANTestCharacter::MoveForward);
PlayerInputComponent->BindAxis("Move Right / Left", this, &ALANTestCharacter::MoveRight);
// We have 2 versions of the rotation bindings to handle different kinds of devices differently
// "turn" handles devices that provide an absolute delta, such as a mouse.
// "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
PlayerInputComponent->BindAxis("Turn Right / Left Mouse", this, &APawn::AddControllerYawInput);
PlayerInputComponent->BindAxis("Turn Right / Left Gamepad", this, &ALANTestCharacter::TurnAtRate);
PlayerInputComponent->BindAxis("Look Up / Down Mouse", this, &APawn::AddControllerPitchInput);
PlayerInputComponent->BindAxis("Look Up / Down Gamepad", this, &ALANTestCharacter::LookUpAtRate);
// handle touch devices
PlayerInputComponent->BindTouch(IE_Pressed, this, &ALANTestCharacter::TouchStarted);
PlayerInputComponent->BindTouch(IE_Released, this, &ALANTestCharacter::TouchStopped);
}
void ALANTestCharacter::OpenLobby()
{
UWorld* World = GetWorld();
if (World)
{
World->ServerTravel("/Game/ThirdPerson/Maps/Lobby?listen");
}
}
void ALANTestCharacter::CallOpenLevel(const FString& Address)
{
UGameplayStatics::OpenLevel(this, *Address);
}
void ALANTestCharacter::CallClientTravel(const FString& Address)
{
APlayerController* PlayerController = GetGameInstance()->GetFirstLocalPlayerController();
if (PlayerController)
{
PlayerController->ClientTravel(Address, ETravelType::TRAVEL_Absolute);
}
}
void ALANTestCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
{
Jump();
}
void ALANTestCharacter::TouchStopped(ETouchIndex::Type FingerIndex, FVector Location)
{
StopJumping();
}
void ALANTestCharacter::TurnAtRate(float Rate)
{
// calculate delta for this frame from the rate information
AddControllerYawInput(Rate * TurnRateGamepad * GetWorld()->GetDeltaSeconds());
}
void ALANTestCharacter::LookUpAtRate(float Rate)
{
// calculate delta for this frame from the rate information
AddControllerPitchInput(Rate * TurnRateGamepad * GetWorld()->GetDeltaSeconds());
}
void ALANTestCharacter::MoveForward(float Value)
{
if ((Controller != nullptr) && (Value != 0.0f))
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
void ALANTestCharacter::MoveRight(float Value)
{
if ( (Controller != nullptr) && (Value != 0.0f) )
{
// find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get right vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, Value);
}
}
E:/Unreal/UE5/LANTest/Content/ThirdPerson/Maps/Lobby.umap 이 복사한 File Path
World->ServerTravel("/Game/ThirdPerson/Maps/Lobby?listen");
BP_ThirdPersonCharacter
Event Graph
프로젝트 패키지 하기 (Package Project)
'⭐ Unreal Engine > UE Multiplayer FPS TPS + ListenServer' 카테고리의 다른 글
[UE] Multiplayer 6: Button Callbacks 만들기, SubSystem 접근하기 (0) | 2023.07.17 |
---|---|
[UE] Multiplayer 5: Plugin: Plugin 만들기, Menu 생성하기 (0) | 2023.07.16 |
[UE] Multiplayer 4: Session 들어가기 (0) | 2023.07.15 |
[UE] Multiplayer 3: Session 생성하기 (0) | 2023.07.15 |
[UE] Multiplayer 2: Online Subsystem Steam (0) | 2023.07.15 |
댓글
이 글 공유하기
다른 글
-
[UE] Multiplayer 5: Plugin: Plugin 만들기, Menu 생성하기
[UE] Multiplayer 5: Plugin: Plugin 만들기, Menu 생성하기
2023.07.16 -
[UE] Multiplayer 4: Session 들어가기
[UE] Multiplayer 4: Session 들어가기
2023.07.15 -
[UE] Multiplayer 3: Session 생성하기
[UE] Multiplayer 3: Session 생성하기
2023.07.15 -
[UE] Multiplayer 2: Online Subsystem Steam
[UE] Multiplayer 2: Online Subsystem Steam
2023.07.15