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);)

 

 

 

 

+ Recent posts