-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFloatCurveActor.cpp
More file actions
57 lines (40 loc) · 1.82 KB
/
FloatCurveActor.cpp
File metadata and controls
57 lines (40 loc) · 1.82 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Fill out your copyright notice in the Description page of Project Settings.
#include "TimelinePluginDemo.h"
#include "FloatCurveActor.h"
void AFloatCurveActor::MoveActor(FVector NewLocation)
{
//Move actor is going to be called with an interpolated value
SetActorLocation(NewLocation);
}
void AFloatCurveActor::RotateActor(FRotator NewRotation)
{
//Will rotate the actor with an interpolated rotation
SetActorRotation(NewRotation);
}
// Sets default values
AFloatCurveActor::AFloatCurveActor()
{
// 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;
SM = CreateDefaultSubobject<UStaticMeshComponent>(FName("SM"));
//Init Component
TimelineHandleComp = CreateDefaultSubobject<UTimelineHandleComponent>(FName("TimelineHandleComp"));
}
// Called when the game starts or when spawned
void AFloatCurveActor::BeginPlay()
{
Super::BeginPlay();
//Add a curve to the component
TimelineHandleComp->AddCurve(FloatCurve);
//Since we're playing a float curve, we're going to interpolate between two values.
//In this case we're going to move our actor forward by 150 units
TimelineHandleComp->SetInitialAndTargetValues(GetActorLocation(), GetActorLocation() + GetActorForwardVector() * 150);
//Moreover, we're going to rotate 180 degrees around Y and X axis
TimelineHandleComp->SetInitialAndTargetValues(GetActorRotation(), GetActorRotation() + FRotator(180.f, 0, 180.f));
//Function to call in each timeline tick
TimelineHandleComp->OnFloatCurveVectorTickFunction.AddDynamic(this, &AFloatCurveActor::MoveActor);
//Function to call for FRotator types
TimelineHandleComp->OnFloatCurveRotatorTickFunction.AddDynamic(this, &AFloatCurveActor::RotateActor);
//Play the timeline from start
TimelineHandleComp->PlayTimelineFromStart();
}