cpp의 Tick은 함수이기 때문에 내부에 변수를 추가하여도 다음 Tick때는 존재하지 않는 변수이다.
그렇기 때문에 Actor의 객체에 변수를 추가하여야한다.
Item.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Item.generated.h"
UCLASS()
class TEST01_API AItem : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AItem();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// 멤버변수 RunningTime
private:
float RunningTime;
};
Item.cpp
void AItem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// 1프레임당 걸리는 시간을 계속 누적한다. 즉 선형적인 값
RunningTime += DeltaTime;
// 사인함수에 선형적으로 증가하는 값을 넣었기 때문에 위아래로 흔들리는 사인함수의 그래프를 얻을 수 있다.
float DeltaZ = FMath::Sin(RunningTime);
CUSTOM_DEBUG_MESH_SingleFrame(GetActorLocation(), GetActorForwardVector() );
AddActorWorldOffset(FVector(0.f ,0.f , DeltaZ));
}
큰 진폭 : ( 2 * FMath::Sin(RunningTime);)
빠른 주기 (FMath::Sin(RunningTime * 5.f);)
'기타 > UnReal Engine' 카테고리의 다른 글
함수의 노출 (UFUNCTION, templateFunction) (0) | 2023.11.21 |
---|---|
멤버변수의 노출(UPROPERTY) (0) | 2023.11.21 |
오브젝트의 이동 (초당 이동거리, Persistent, AddActorWorldOffser) (0) | 2023.11.21 |
Actor의 위치 디버깅(DrawDebugSphere) (0) | 2023.11.18 |
언리얼 엔진 레벨 연습 (0) | 2023.11.13 |