In this lesson, when I was working this on my own, I looked up the FVector API and found FVector::Distance(). I used this in my code rather than Magnitude as shown… is there any reason we couldn’t use this function for the purposes of moving the platform?
My current code that uses this:
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if(HasAuthority()){
FVector CurrentLocation = GetActorLocation();
if(FVector::Distance(CurrentLocation, GlobalStartLocation) > FVector::Distance(GlobalTargetLocation, GlobalStartLocation))
{
FVector Holder = GlobalStartLocation;
GlobalStartLocation = GlobalTargetLocation;
GlobalTargetLocation = Holder;
}
FVector Direction = (GlobalTargetLocation - GlobalStartLocation).GetSafeNormal();
CurrentLocation += Direction * DeltaTime * PlatformSpeed;
SetActorLocation(CurrentLocation);
}
}