Instead of doing like was done in the video, I made the following:
void UMover::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
float Speed;
if(bShouldMove)
{
FVector TargetLocation = OriginalLocation + MoveOffset;
Speed = FVector::Distance(OriginalLocation, TargetLocation) / MoveTime;
MoveToLocation(DeltaTime, TargetLocation, Speed);
}
else
{
FVector StartLocation = OriginalLocation + MoveOffset;
Speed = FVector::Distance(StartLocation, OriginalLocation) / MoveTime;
MoveToLocation(DeltaTime, OriginalLocation, Speed);
}
}
void UMover::MoveToLocation(float DeltaTime, FVector ToLocation, float Speed)
{
FVector CurrentLocation = GetOwner()->GetActorLocation();
FVector NewLocation = FMath::VInterpConstantTo(CurrentLocation, ToLocation, DeltaTime, Speed);
GetOwner()->SetActorLocation(NewLocation);
}
I did not see any difference between my result and the answer, but I’m curious about what you guys thinl.