I am already struggling 3 days with this, I translated some parts but all is bad, can anyone help me to give me a clean and simple example of this graph in C++, to get the spring arm I am using characterref variable in the class playercotroller, you can take spring arm directly in character class or as you want.
#include "Components/TimelineComponenet.h"
MyCharacter::MyCharacter() //constructor
{
static ConstructorHelpers::FObjectFinder<UCurveFloat> Curvy(TEXT("Refference to your float curve"));
if (Curvy.Object)
{
fCurve = Curvy.Object;
}
//Timeline components don't need to be attached/connect to anything.
TL_UpdateCameraHeight = CreateDefaultSubobject<UTimelineComponent>(TEXT("TL_UpdateCameraHeight"));
//Binging Delegates with UFunctions
InterpFunction.BindUFunction(this, FName("TL_HeightUpdateFunc"));
TimelineFinished.BindUFunction(this, FName("TL_HeightUpdateFinished"));
}
if (_CurrentHeight != _NewHeight) //checking camera height according to the character pose
{
_OriginalHeight = _CurrentHeight; //Sets the value of Current height to Original height
//check if curve is refference asset is valid
if(fCurve)
{
//Add the float curve named "Percent" to the timeline and connect to the interpfunction's delegate
TL_UpdateCameraHeight->AddInterpFloat(fCurve, InterpFunction, FName("Percent"));
//Add timeline finished function
TL_UpdateCameraHeight->SetTimelineFinishedFunc(TimelineFinished);
//Vectors
StartLocation = GetActorLocation();
EndLocation = FVector(StartLocation.x, StartLocation.y, StartLocation.z = ZOffset);
//Setting Timeline Settings before we start it
TL_UpdateCameraHeight->SetLooping = false;
TL_UpdateCameraHeight->SetIgnoreTimeDilation = true;
//Start Timeline
TL_UpdateCameraHeight->PlayFromStart();
}
}
void MyCharacter::TL_HeightUpdateFunc(float Value)
{
SetActorLocation(FMath::Lerp(_OriginalHeight, _NewHeight, Value));
}
void MyCharacter::TL_HeightUpdateFinished(float Value)
{
if(TL_UpdateCameraHeight->GetPlaybackPosition() == 0.0f)
{
TL_UpdateCameraHeight->PlayFromStart();
}
}
Thank You very very much, I was struggling with this for 3 days and SpringArm->GetRelativeLocation();USpringArmComponent has no member GetRelativeLocation()
IDE will show you a lot of red underlinings when you code. Intellisense often doesn’t really catch up with the engine classes. So try and compile things first, then look for errors =)
Just checked to be sure, SpringArm->GetRelativeLocation() compiles fine. use of undefined type USpringArmComponent shows up if there’s no respective #include
There must be something else you’re missing.
How it’s setup in my project:
.h:
UPROPERTY(EditAnywhere)
class USpringArmComponent* SpringArm;
.cpp:
#include "GameFramework/SpringArmComponent.h"
// In constructor:
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(GetCapsuleComponent());
//In a function:
SpringArm->GetRelativeLocation();
This in fact might have changed. I believe CapsuleComponent was public, then at some point it was moved to private, and public GetCapsuleCompoent() was added. You can try simply something like SetupAttachment(CapsuleComponent)