티스토리 뷰

카테고리 없음

Unreal 4 입문 #4

빅토리아레몬탄산수 2021. 7. 29. 19:48

Unreal QuickStart를 만들어볼 예정입니다.

Actor - 레벨에 배칠 될 수 있는 오브젝트

C++ 클래스 생성 후 Actor 클래스로 이름은 FloatingActor로 생성합니다.

FVector - 언리얼내에서 위치와 속도를 다루기 위한 타입

헤더 파일엔

Tick에서 사용할 float RunningTime;을 선언해줍니다.

그리고 FloatingActor.cpp에 위아래로 움직이게 하도록합니다.

void AFloatingActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FVector NewLocation = GetActorLocation();
	float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
	NewLocation.Z += DeltaHeight * 20.0f;
	RunningTime += DeltaTime;
	SetActorLocation(NewLocation);
}

작성하고 컴파일 해줍니다. 그리고 작성한 FloatingActor 클래스를 찾아서 레벨 에디터에 끌어다 놓으면 FloatingActor의 인스턴스가 생성됩니다. 생성된 파일은 이름1 이렇게 이름이 지어진 채로 아웃라이너에서 확인가능합니다. 하지만 레벨 에디터에서 확인이 불가합니다. 그래서 한가지 과정을 거칩니다.

아웃라이너에서 FloatingActor1을 찾아서 선택합니다. 그리고 컴포넌트 추가를 해서 원뿔을 추가해줍니다. 그럼 원뿔 모양이 생기고 잘 보이도록 책상 위에 둡니다. 그럼 이제 게임 실행을 하면 위아래로 움직이는 원뿔 모양을 볼 수 있습니다.

float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));

이렇게 해주면 사인그래프를 따라서 오브젝트가 동작하는 시간 동안 델타타임이 더 해져서 앞서나가는 값과 원본값의 차이를 구해서 Actor가 얼마나 위아래로 움직여야하는지 그값을 구할 수 있게 됩니다.

실질적으로 SetActorLocation함수 움직이며 움직여야하는 값은 NewLocation.Z = DeltaHeight * 속도,에서 계속해서 넘겨줍니다.

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FVector MoveSpeed;

디테일에서 스피드를 프로퍼티를 수정 가능하게 했습니다.

그리고 XYZ축의 움직임을 주기 위해서 코드를 수정하겠습니다.

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


#include "FloatingActor.h"

// Sets default values
AFloatingActor::AFloatingActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	MoveSpeed = FVector(1.0f,1.0f,1.0f);
}

// Called when the game starts or when spawned
void AFloatingActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AFloatingActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FVector NewLocation = GetActorLocation();
	float DeltaX = (FMath::Sin(RunningTime.X + DeltaTime) - FMath::Sin(RunningTime.X));
	float DeltaY = (FMath::Sin(RunningTime.Y + DeltaTime) - FMath::Sin(RunningTime.Y));
	float DeltaZ = (FMath::Sin(RunningTime.Z + DeltaTime) - FMath::Sin(RunningTime.Z));
	NewLocation += FVector(DeltaX,DeltaY,DeltaZ) * 20.0f;
	RunningTime += DeltaTime * MoveSpeed;
	SetActorLocation(NewLocation);
}

파티클은 컴포넌트 추가로 ParticleSystem을 추가하면 파티클이 생성됩니다.

이렇게 Quick Start는 완료했습니다.

최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함