My code:
void ABoxStaticMeshActor::BeginPlay()
{
Super::BeginPlay();
if (!HasAuthority())
{
return;
}
StartLocation = GetActorLocation();
ToLocation = GetTransform().TransformPosition(TargetLocation);
SetReplicates(true);
SetReplicateMovement(true);
}
void ABoxStaticMeshActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!HasAuthority())
{
return;
}
MoveToTarget(DeltaTime);
}
void ABoxStaticMeshActor::MoveToTarget(float DeltaTime)
{
FVector Location = GetActorLocation();
Location = FMath::VInterpTo(Location, ToLocation, DeltaTime, Speed);
SetActorLocation(Location);
if (Location.Equals(ToLocation, 20.f))
{
Swap(ToLocation, StartLocation);
}
}
I realize there’s a bit of error tolerance, but readability seems better. Is the reason we don’t use Equals here just due to the lack of exactness?
Not that I’m complaining, I liked the detailed math explanations/alternative techniques!