하아찡

[언리얼5] 서버 캐릭터 움직임 처리 본문

C++/이것저것서버테스트

[언리얼5] 서버 캐릭터 움직임 처리

하아찡 2025. 2. 16. 23:20

언리얼 버전 5.5.3

서버언어 C++로 구성했습니다.

 

 

 

아래 코드는 캐릭터 코드 중 움직임 처리하는 부분입니다.

기존애 존재하는 Move 함수에 SendMove를 추가하여 움직인 데이터를 서버에 전송합니다.

void AlllllllllqqqCharacter::SendMove()
{

	// 움직인 후 값받아옴
	const FVector Location = Controller->GetPawn()->GetActorLocation();
	const FRotator MoveRotation = Controller->GetControlRotation();
	float Yaw = MoveRotation.Yaw;

	if (auto* GameInstance = Cast<UMyGameInstance>(GWorld->GetGameInstance()))
	{
		// 움직임 처리
		Protocol::C_MOVE movePkt;
		Protocol::PlayerInfo* player = new Protocol::PlayerInfo();
		player->set_object_id(GameInstance->MyObjectId);
		player->set_x(Location.X);
		player->set_y(Location.Y);
		player->set_z(Location.Z);
		player->set_yaw(Yaw);
		movePkt.set_allocated_players(player);
		
		// TODO : 보정작업 추가
		
		SEND_PACKET(movePkt);

	}
	
}

void AlllllllllqqqCharacter::Move(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D MovementVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	
		// get right vector 
		const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

		// add movement 
		AddMovementInput(ForwardDirection, MovementVector.Y);
		AddMovementInput(RightDirection, MovementVector.X);

		// 움직임을 서버에 보냄
		SendMove();
	}
}

 

문제점.

1. 액터를 위치값을 건들다보니 애니메이션이 작동하지않음. -> 걷는 모션이 작동하지않음. 다른방법으로 수정해야함.

2. 움직일때 마다 서버에 움직임 데이터를 보내다보니 너무 많은 데이터가 들어감. 약간의 보정처리를 해줘야할듯.

 

추가해야될점.

1. 점프 처리를 아직하지않음. 구성은 어떻게 해야할지 고민중. 일단 생각한건 점프패킷을 하나 만들어서 점프할때 패킷을 보내도록 추가할듯함.

2. 시선처리 -> 이것도 과도하게 데이터를 보낼거같으니 움직임 보정처리할때 비슷하게 처리하면 될듯함.

 

 

반응형

'C++ > 이것저것서버테스트' 카테고리의 다른 글

[언리얼5, C++] 맵 이동 - 2  (0) 2025.02.25
[언리얼5, C++] 맵 이동  (0) 2025.02.23
[C++서버] 서버 채널 분할  (0) 2025.02.21
[언리얼5] 채팅  (0) 2025.02.20
[언리얼5] 서버 캐릭터 움직임 처리 - 2  (0) 2025.02.18