[UE5] Vector

GamzaTori·2024년 9월 26일

UE5 C++

목록 보기
3/27
  • x, y, z 축 좌표에 대한 정보를 가지고 있는 구조체
    FVector(double x, double y, double z)
    FVector v;
    
    v.Length();  // 벡터의 크기
    v.Normalize();  // 벡터의 방향
    • 크기와 방향을 가지고 있다
  • 특정 방향으로 액터를 이동시키는 방법
    float Speed = 50.0f;
    float Distance = DeltaTime * Speed;
    
    FVector Location = GetActorLocation();
    	
    FVector NewLocation= Location * FVector::ForwardVector * Distance;;
    //SetActorLocation(NewLocation);	
    
    AddActorWorldOffset(FVector::ForwardVector * Distance);  // 방향벡터로만 알아서 움직여줌 
  • 특정 Target을 따라가도록 만들어보자
    // header
    UPROPERTY(EditAnywhere, Category = Battle)
    TObjectPtr<class AActor> Target;
    
    // cpp
    float Speed = 50.0f;
    float Distance = DeltaTime * Speed;
    
    FVector Location = GetActorLocation();
    
    FVector DirectionVector = Target->GetActorLocation() - GetActorLocation();
    DirectionVector.Normalize();
    
    FVector NewLocation= Location * DirectionVector * Distance;;
    
    //SetActorLocation(NewLocation)
    AddActorWorldOffset(DirectionVector*Speed);
  • 현재 맵에 있는 특정 Actor를 찾는 방법
    Target = UGameplayStatics::GetActorOfClass(GetWorld(), ARActor::StaticClass());   // 해당 클래스 이거나 파생된 액터를 찾아온다
    
    TArray<AActor*> Actors;
    UGameplayStatics::GetAllActorsOfClass(GetWorld(), ARActor::StaticClass(), OUT Actors);   // 해당 클래스 이거나 파생된 액터를 찾아온다
    
    UGameplayStatics::GetAllActorsWithTag(GetWorld(), TEXT("R"), OUT Actors);	  // Tag를 통해 액터를 찾아오는 방법
    
    // Actors.Empty();  // -> STL의 Vector.Clear()와 같다
    if(Actors.Num() > 0)  // 카운팅을 통해 비어있는지 확인할 수 있다
    {
    	//
    }
profile
게임 개발 공부중입니다.

0개의 댓글