Maybe I need to try FVector CurrentLocation = SpringArm->GetComponentLocation(); if it will give me the same result as GetRelativeLocation()
No, it will give you world location of the component. But you can subtract the character location from that to get relative location.
FVector CurrentLocation = SpringArm->GetComponentLocation()
FVector CharacterLocation= CharacterMesh->GetActorLocation()
FVector RelativeLocation = (CurrentLocation - CharacterLocation);
Something like this?
FVector CharacterLocation = GetActorLocation();
Since your spring arm is attached to RootComponent, not to CharacterMesh.
Plus CharacterMesh is a component, is doesn’t have GetActorLocation() function;
I tried with UE-4.23 GetRelativeLocation() compiles without any error.
I have shortened the whole setup.
Please tell me if I have any mistake in my whole setup according to the BP graph.
.h
class UTimelineComponent* TL_UpdateCameraHeight; // TimeLine Global Class
UPROPERTY(EditAnywhere, Category = "Timeline")
class UCurveFloat* fCurve;
FOnTimelineFloat InterpFunction{}; //Delegate to bind TL_HeightUpdateFunc
UFUNCTION()
void TL_HeightUpdateFunc(float value); //update
.cpp
MyCharacter::MyCharacter()
{
static ConstructorHelpers::FObjectFinder<UCurveFloat> Curvy(TEXT("Reference to the Curve float '"));
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"));
TL_UpdateCameraHeight->PlayFromStart();
}
}
void MyCharacter::TL_HeightUpdateFunc(float value)
{
FVector CurrentLocation = SpringArm->GetRelativeLocation();//Get Springarm relative location
float NewHeight = FMath::Lerp(_OriginalHeight, _NewHeight, value); //Lerp
SpringArm->SetRelativeLocation(FVector(CurrentLocation.X, CurrentLocation.Y, NewHeight)); //Set Springarm Relative location
}
I found on google something about the engine 4.20 , is actually need
FVector CurrentLocation = GetTransform().InverseTransformPosition(SpringArm->GetComponentLocation());
not sure if it will get the location correctly, but the animation is now playing properly just arm is not changing the location according to the pose of the character.
InverseTransformPosition is transforming location from world to relative; if actor scale is 1, it will basically do the same as simply subtracting locations.
Just as a test, try casting your spring arm to scene component and see what happens:
USceneComponent* MyScene = Cast<USceneComponent>(SpringArm);
if (MyScene != nullptr)
{
MyScene->GetRelativeLocation();
}
Ok , I will try it now, will let you know in a moment …
Same Error, I have checked the SceneComponent.h and it has GetRelativeLocation(); commented.
I am afraid if I uncomment it and rebuild the engine, it will break things.
Maybe RelativeLocation was public in 4.20, too.
Try simply SpringArm->RelativeLocation;
Plus you should always look for the things you need in parent classes. Maybe try ->GetRelativeTransform()
or just ->RelativeTransform;
maybe these will get something.
I just tried FVector CurrentLocation = SpringArm->RelativeLocation; and it works, thank You very much for solving the problem.