Unreal Engine5/KDT 2024
[UE5 KDT2024] 26. 서버에서 충돌처리 2
유잉유잉유잉
2025. 3. 10. 00:05
728x90
▶️ 코드에서 RPC 함수 호출 할 땐 Implementation 가 붙어있지 않은 함수명으로 호출해야 한다.
Implementation 가 붙어있지 않은 함수명으로 호출하면
언리얼에서 구현된 Implementation()을 추적하여 호출하게 된다.
// 호출 : Server_AttackCollision
// 구현 : Server_AttackCollision_Implementation
void Server_AttackCollision();
void Server_AttackCollision_Implementation();
1. 충돌을 서버에서 처리하도록 작업해보자
1) 충돌 서버처리함수 추가
UFUNCTION( BlueprintCallable, Server, Reliable )
void AttackCollision_Server();
void AttackCollision_Server_Implementation();
2) AttackBegin에서 처리하던 충돌 처리를 AttackCollision_server로 이동
void APlayerKnight::AttackBegin()
{
AttackCollision_Server();
}
AttackBegin()에선 AttackCollision_Server(); 호출
void APlayerKnight::AttackCollision_Server_Implementation()
{
FVector start = GetActorLocation() + GetActorForwardVector() * 50.f;
FVector end = start + GetActorForwardVector() * 400.f;
FCollisionQueryParams params;
params.AddIgnoredActor( this );
TArray<FHitResult> result;
bool collision = GetWorld()->SweepMultiByChannel( result, start, end, FQuat::Identity,
ECollisionChannel::ECC_GameTraceChannel4,
FCollisionShape::MakeSphere( 50.f ), params );
// 디버그일때만 그린다.
#if ENABLE_DRAW_DEBUG
FColor drawColor = collision ? FColor::Red : FColor::Green ;
DrawDebugLine( GetWorld(), start, end, drawColor, false, 1.0, 0, 50.f );
#endif
// 충돌된 물체가 있다면
if ( collision )
{
// Ranged For
for ( const FHitResult& hit : result )
{
// 파티클 (이펙트) 출력
UParticleSystem* particle = LoadObject<UParticleSystem>( nullptr, L"/Script/Engine.ParticleSystem'/Game/ParagonAurora/FX/Particles/Abilities/Primary/FX/P_Aurora_Melee_SucessfulImpact.P_Aurora_Melee_SucessfulImpact'" );
FVector loc = hit.Location;
UParticleSystemComponent* particleCp = UGameplayStatics::SpawnEmitterAtLocation( GetWorld(), particle, loc, GetActorRotation(), true );
}
}
}
=> 여기까지 작업 후 실행하면 서버일때만 충돌처리, 파티클 생성이 된다.
3) 모든 클라에게 파티클 생성이 되게 해보자.
AttackCollision_Server_Implementation()에서 충돌 감지 for문에서
이펙트 출력을 SpawnEffect_MultiCast( hit.Location );로 대체하여 다른 클라들도 이펙트가 발생되도록 해준다.
void APlayerKnight::AttackCollision_Server_Implementation()
{
...
// 충돌된 물체가 있다면
if ( collision )
{
// Ranged For
for ( const FHitResult& hit : result )
{
// 서버에 연결된 모든 클라이언트들에게 이펙트 출력
SpawnEffect_MultiCast( hit.Location );
}
}
}
=> 실행하면 서버, 클라 모두 이펙트가 잘 출력된다.
2. 지형 편집 툴
1)
선택모드 -> 랜드스케이프모드를 이용해서 지형 변경 가능
2) 스컬프팅 -> 땅올라옴
3) 물 넣기
편집 - 플러그인 - water 검색해서 추가 후 재시작 -
만들어서 직접 수정가능하다.
요샌 맵 모델링 바로 깔아서 사용해서 잘 안쓰는 기술이긴 하다.
3. 언리얼 에디터 언어 영어로 변경하기
language=ko로 바꾸면 다시 한글로 변환된다.
728x90