In MovingPlatform.h
....
protected:
FVector WorldStartLocation;
FVector WorldEndLocation;
float LerpAlpha = 0.0f;
float LerpStep = 0.0f;
...
In MovingPlatform.cpp
...
void AMovingPlatform::BeginPlay()
{
Super::BeginPlay();
if (HasAuthority()) {
SetReplicates(true);
SetReplicateMovement(true);
WorldStartLocation = GetActorLocation();
WorldEndLocation = WorldStartLocation + TargetLocation;
FVector Distance = WorldEndLocation - WorldStartLocation;
LerpAlpha = 0;
LerpStep = MovementSpeed/Distance.Size();
}
}
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (HasAuthority()) {
LerpAlpha += LerpStep*DeltaTime;
SetActorLocation(FMath::Lerp(WorldStartLocation, WorldEndLocation, LerpAlpha));
if (LerpStep > 0 && LerpAlpha >= 1 || LerpStep < 0 && LerpAlpha <= 0) {
LerpStep *= -1;
}
}
}