공부/언리얼 엔진

언리얼 엔진 공부 31 - 범위 지정 연산자(Scope Resolution Operator)

라이티아 2025. 8. 1. 15:55

플렛폼의 이동 거리를 확인하고 계산함

 

두 벡터의 차이값을 찾아야함

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MovingPlatform.generated.h"

UCLASS()
class OBSTACLEASSAULT_API AMovingPlatform : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMovingPlatform();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere, Category="Moving Platform")
	FVector PlatformVelocity = FVector(100, 0, 0);

	FVector StartLocation;
};

startlocation을 생성해줌

void AMovingPlatform::BeginPlay()
{
	Super::BeginPlay();
	
	StartLocation = GetActorLocation();
}

이를 begin play에서 초기화해줌

 

 

Scope Resolution Operator :: 범위 지정 연산자 

클래스 안에 뭐가 있는지 확인

 

현재는 FVector class의 함수를 사용함

FVector::Dist(StartLocation, CurrentLocation);

이렇게 할시 각 vector사이의 거리를 float로 반환하는 함수를 사용할 수 있음

 

	UPROPERTY(VisibleAnywhere)
	float LookDist = -1;

h에 확인용 값을 만든 뒤

	LookDist = FVector::Dist(StartLocation, CurrentLocation);

cpp에서 해당 값을 가져옴

컴파일 후 확인을 해보면 거리값이 확인이 되는 것을 볼 수 있음