1. 현재 메쉬의 스케일을 업데이트 계속해서 업데이트
2. 최솟값보다 작아지면 커지도록, 최댓값보다 커지면 작아지도록 --> 스케일 변경 속도값의 부호를 반전
/********** .h file *****************/
// 1. CurrScale : keeps track of current scale
// 2. MaxScale, MinScale : Maximum and minimum value for current scale
// 3. SpeedScale : speed at which scale changes
FVector CurrScale;
float MinScale, MaxScale, SpeedScale;
/*********** .cpp file **************/
// Variable initialized in constructor
AMyActor::AMyActor()
{
//...
CurrScale = FVector(2.f);
MinScale = 1.f;
MaxScale = 3.f;
SpeedScale = 1.f;
}
// Set relative scale of the static mesh component, which is attached to root component
void BeginPlay()
{
//...some code to initialize components and set up attachments...
StaticMeshComp->SetRelativeScale3D(CurrScale);
}
// Scale gets updated and reflected in Tick:
void Tick(float DeltaTime)
{
// Reverse direction of scale change
if (CurrScale.Z >= MaxScale || CurrScale.Z <= MinScale)
{
SpeedScale *= -1;
}
if (!FMath::IsNearlyZero(SpeedScale * DeltaTime))
{
// Multiply DeltaTime to keep it frame rate independent
CurrScale += FVector(SpeedScale * DeltaTime);
StaticMeshComp->SetRelativeScale3D(CurrScale);
}
}
'언리얼_엔진_게임개발_공부 > 언리얼 C++' 카테고리의 다른 글
[언리얼/C++] 타이머 사용하기 / FTimerManager, FTimerHandle, SetTimer() (0) | 2025.01.24 |
---|---|
[언리얼/C++] 열거형 - UENUM / 언리얼 엔진의 EAxis (0) | 2025.01.23 |
[언리얼/C++] 비트마스크 Bitmask / TryFindType, UnknownFunction 경고 해결 (1) | 2025.01.21 |
[언리얼/C++] 액터에 컴포넌트 추가 및 에셋 적용 (1) | 2025.01.20 |
(과제용) Unreal Engine C++ 간단한 이동 로직 구현하기 (0) | 2025.01.06 |