FMath::VInterpTo is not working the way i expect it

guys pls help me with this code I’m trying to move a wall to a certain location when the player overlaps with a switch but instead of a smooth transition the wall just jumps to the new location which is not what I want

void AFloatingPlatform::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
FVector CurrentLocation = Wall->GetComponentLocation();
FVector NewLocation = FMath::VInterpTo(CurrentLocation, EndPoint, GetWorld()->GetDeltaSeconds(), InterpSpeed);

Wall->SetWorldLocation(NewLocation);

UE_LOG(LogTemp, Warning, TEXT(“Overlapping”));
}

Hi,

I believe there is another interpolation function which is VInterpToConstant().

The VinterpTo version is meant for motion that has a faster start speed and slower end speed; the VInterpToConstant() has a constant speed from start to end - which is likely the one you are looking for,

I hope this post can help you with your problem. =)

If you’re not triggering *OnBeginOverlap *continuously, then you’re using *VInterpTo *wrong. Check this: https://forums.unrealengine.com/deve…implementation, to realize what’s the problem is:

Also, are you moving an actor or a component? If the latter, then consider to use UKismetSystemLibrary::MoveComponentTo. Unlike the Lerp functions, this function doesn’t requires continuous execution.

i’m moveing a component. my actor has 2 meshes and 1 collision box so 1 of them needs to move and the other one is a switch which is supposed to trigger the function.

guys i’m a noob in c++ can anybody tell me why it’s not moving?

void AFloatingPlatform::BeginPlay()
{
Super::BeginPlay();

FloatingTrigger->OnComponentBeginOverlap.AddDynamic(this, &AFloatingPlatform::OnBeginOverlap);
FloatingTrigger->OnComponentEndOverlap.AddDynamic(this, &AFloatingPlatform::OnEndOverlap);
}

// Called every frame
void AFloatingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

void AFloatingPlatform::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{

FLatentActionInfo LatentInfo;

UKismetSystemLibrary::MoveComponentTo(Wall, EndPoint, FRotator(0.f), true, true, InterpSpeed, true, EMoveComponentAction::Type::Move, LatentInfo );

UE_LOG(LogTemp, Warning, TEXT(“Begin Overlap”));
}

That’s what Interp actually does, you need to call it repeatedly from a Tick or Timer using a low InterpSpeed, so it moves a little bit every frame (that’s why it takes a DeltaTime argument).

when I put the function call in tick it shows strange behavior. the wall moves halfway through but then stops even tho in output log i see that the function is being called everyframe, the component doesnt get to the Endpoint it just stops between the 2 points and when i start overlapping again it goes to the endpoint.

One thing is missing (the callback) and other is wrong (not the speed but the time).



FLatentActionInfo LatentInfo;
**LatentInfo.CallbackTarget = this;**
UKismetSystemLibrary::MoveComponentTo(Wall, EndPoint, FRotator(0.f), true, true, **TOTAL_TIME_FOR_THE_MOVEMENT,** true, EMoveComponentAction::Type::Move, LatentInfo );


Also, make sure the EndPoint is relative and not absolute.

omg finally! Thank you bro i love u

I had similar problem …
VInterp in C++ does not work as expected for slow speeds, if you want to slowly interp something …
And yes, even if you call it on Tick, same result …

MoveToComponent seems to be the magic most flexible solution for this so far …