My current code is:
if(ShouldMove == true)
{
FVector CurrentLocation = GetOwner() -> GetActorLocation();
FVector TargetLocation = OriginalLocation + MoveOffset;
float Speed = FVector::Distance(OriginalLocation, TargetLocation) / MoveTime;
FVector NewLocation = FMath::VInterpConstantTo(CurrentLocation, TargetLocation, DeltaTime, Speed);
GetOwner() -> SetActorLocation(NewLocation);
}
else
{
FVector CurrentLocation = GetOwner() -> GetActorLocation();
float Speed = FVector::Distance(CurrentLocation, OriginalLocation) / MoveTime;
FVector NewLocation = FMath::VInterpConstantTo(CurrentLocation, OriginalLocation, DeltaTime, Speed);
GetOwner() -> SetActorLocation(NewLocation);
}
This works however the wall slows down as it goes back up. I’m guessing the distance is recalculated each time, instead of there being a unaffected variable for current location like there is for OriginalLocation.
Would I need to set a new variable outside the tick function such Speed?