KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
ConveyorBelt.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
3
4#include "ConveyorBelt.h"
5
6#include "ANPCBase.h"
7#include "APlayerActor.h"
8#include "Food.h"
9#include "GameLogging.h"
11#include "luggage.h"
12#include "Components/ArrowComponent.h"
13#include "Components/BoxComponent.h"
14
15
16// Sets default values
18{
19 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
20 PrimaryActorTick.bCanEverTick = true;
21
22 RootSceneComp = CreateDefaultSubobject<USceneComponent>(TEXT("RootSceneComp"));
23 SetRootComponent(RootSceneComp);
24
25 BeltComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BeltComp"));
26 ConstructorHelpers::FObjectFinder<UStaticMesh> beltMeshRef(TEXT("/Script/Engine.StaticMesh'/Game/LevelPrototyping/Meshes/SM_ChamferCube.SM_ChamferCube'"));
27 if (beltMeshRef.Succeeded())
28 {
29 BeltComp->SetStaticMesh(beltMeshRef.Object);
30 BeltComp->SetRelativeScale3D(FVector(1.5,5.5,0.05));
31 BeltComp->SetupAttachment(GetRootComponent());
32 }
33
34 BeltBoxComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BeltBoxComp"));
35 BeltBoxComp->SetupAttachment(GetRootComponent());
36 BeltBoxComp->SetBoxExtent(FVector(75,275,5));
37
38 MoveDirArrowComp = CreateDefaultSubobject<UArrowComponent>(TEXT("MoveDirArrowComp"));
39 MoveDirArrowComp->SetupAttachment(GetRootComponent());
40 MoveDirArrowComp->SetRelativeRotation(FRotator(0, 90, 0));
41
42 // Set Collision Preset
43 BeltComp->SetCollisionProfileName(TEXT("BlockAllDynamic"));
44 BeltBoxComp->SetCollisionProfileName(TEXT("ConveyorBelt"));
45}
46
47// Called when the game starts or when spawned
49{
50 Super::BeginPlay();
51
52}
53
59void AConveyorBelt::Tick(float DeltaTime)
60{
61 Super::Tick(DeltaTime);
62
63 // [개선] 서버에서만 이동 처리
64 if (!HasAuthority())
65 return;
66
69}
70
75
76void AConveyorBelt::ServerRPC_InitConveyorBelt_Implementation()
77{
79}
80
81void AConveyorBelt::MulticastRPC_InitConveyorBelt_Implementation()
82{
83 bIsForward = true;
84}
85
90
91void AConveyorBelt::ServerRPC_ChangeConveyorMovement_Implementation()
92{
94}
95
96void AConveyorBelt::MulticastRPC_ChangeConveyorMovement_Implementation()
97{
99 // PRINT_STRING(TEXT("%d"), bIsForward);
100}
101
103{
105}
106
107void AConveyorBelt::Multicast_ChangeConveyorSpeed_Implementation(float NewSpeed)
108{
109 MoveSpeed = NewSpeed;
110}
111
112void AConveyorBelt::Server_ChangeConveyorSpeed_Implementation(float NewSpeed)
113{
115}
116
118{
119 TArray<AActor*> overlappedActors;
120 BeltBoxComp->GetOverlappingActors(overlappedActors);
121 for (const auto& actor : overlappedActors)
122 {
123 if (Cast<APlayerActor>(actor) || Cast<ANPCBase>(actor))
124 {
125 FVector deltaLoc = MoveDirArrowComp->GetForwardVector() * deltaDistance;
126 deltaLoc = bIsForward ? deltaLoc : -deltaLoc;
127 actor->AddActorWorldOffset(deltaLoc);
128 }
129 }
130}
131
143{
144 TArray<UPrimitiveComponent*> overlappedComponents;
145 BeltBoxComp->GetOverlappingComponents(overlappedComponents);
146
147 for (const auto& comp : overlappedComponents)
148 {
149 AActor* owner = comp->GetOwner();
150 Aluggage* luggage = Cast<Aluggage>(owner);
151 AFood* Food = Cast<AFood>(owner);
152
153 if (!Food && !luggage) continue; // 둘 다 아니면 스킵
154 if (!Cast<UStaticMeshComponent>(comp)) continue;
155
156 // [개선] Luggage의 경우 Hook이나 PickUp 중이면 컨베이어 이동 무시
157 // bIsPickedUp은 이제 복제되므로 서버에서 정확한 상태 확인 가능
158 if (luggage)
159 {
160 if (luggage->InteractableComp && luggage->InteractableComp->IsPickedUp())
161 {
162 continue;
163 }
164
165 // [개선] Hook 중이면 컨베이어 이동 무시
166 if (luggage->bIsBeingHooked)
167 {
168 continue;
169 }
170 }
171
172 FVector moveDirection = MoveDirArrowComp->GetForwardVector();
173 moveDirection = bIsForward ? moveDirection : -moveDirection;
174
175 // 물리 객체인지 확인
176 UPrimitiveComponent* primComp = Cast<UPrimitiveComponent>(comp);
177 if (primComp && primComp->IsSimulatingPhysics())
178 {
185 FVector targetVelocity = moveDirection * MoveSpeed;
186 FVector currentVelocity = primComp->GetPhysicsLinearVelocity();
187
188 // Z축 속도는 현재 속도 유지 (중력, 점프 등)
189 FVector newVelocity = targetVelocity;
190 newVelocity.Z = currentVelocity.Z;
191
192 primComp->SetPhysicsLinearVelocity(newVelocity, false);
193 }
194 else
195 {
196 // 물리가 아닌 경우 (Hook/PickUp 중) - 이동하지 않음
197 // Hook 중에는 물리가 꺼져있으므로 여기서 멈춤
198 }
199 }
200}
Declares the player-controlled character actor.
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
void InitConveyorBelt()
void MulticastRPC_InitConveyorBelt()
void Multicast_ChangeConveyorSpeed(float NewSpeed)
virtual void Tick(float DeltaTime) override
컨베이어 벨트 Tick
TObjectPtr< class USceneComponent > RootSceneComp
void ServerRPC_InitConveyorBelt()
void Server_ChangeConveyorSpeed(float NewSpeed)
TObjectPtr< class UStaticMeshComponent > BeltComp
TObjectPtr< class UBoxComponent > BeltBoxComp
void ServerRPC_ChangeConveyorMovement()
TObjectPtr< class UArrowComponent > MoveDirArrowComp
void MulticastRPC_ChangeConveyorMovement()
void ChangeConveyorSpeed(float NewSpeed)
void MoveOverlappedStatics(float deltaDistance)
정적 오브젝트 (Luggage) 이동 처리
void MoveOverlappedSkeletals(float deltaDistance)
void ChangeConveyorMovement()
virtual void BeginPlay() override
Definition Food.h:37
상호작용 가능한 수하물 액터
Definition luggage.h:15
bool bIsBeingHooked
훅 중 플래그 (복제됨)
Definition luggage.h:55
TObjectPtr< class UInteractableComponent > InteractableComp
Definition luggage.h:38