I created moving tiles that I want to spawn in once my game starts and when i press play i get this weird bug where a second tile appears out of nowhere and starts moving as the original tile goes back to its starting point.
video evidence: Desktop 2021.08.26 - 23.16.26.01.mp4 - Google Drive
the code that i think is the issue:
void AFloatingTiles::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (bInterping) {
FVector CurrentLocation = GetActorLocation();
FVector Interp = FMath::VInterpTo(CurrentLocation, EndPoint, DeltaTime, InterpSpeed);
SetActorLocation(Interp);
float DistanceTraveled = (GetActorLocation() - StartPoint).Size();
if (Distance - DistanceTraveled <= 1.f) {
if (bSpawning) {
bSpawning = false;
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
AFloatingTiles* NewTiles = GetWorld()->SpawnActor<AFloatingTiles>(FloatingTiles, StartPoint, Rotation);
NewTiles->StartPoint = FVector(0.f, 0.f, 0.f);
NewTiles->StartPoint = FVector(100.f, 100.f, 100.f);
}
ToggleInterping();
GetWorldTimerManager().SetTimer(InterpTimer, this, &AFloatingTiles::ToggleInterping, InterpTime);
SwapVectors(StartPoint, EndPoint);
}
}
}