0
\$\begingroup\$

I'm trying to make sure that when the camera reaches the border (left or right) of the sprite's background, a copy of it is spawned from the corresponding side. But I seem to be missing something in the Unreal Engine.

Now I define the intersection of the camera and the sprite boundary as follows:

  1. I take the X coordinate of the sprite and subtract half of its size. (Get it's left border)
  2. I also take the camera coordinate and subtract half of the orthographic length (Left border of a screen?)
    ParallaxItems[Index]->GetActorBounds(false, ActorOrigin, BoxExtent, false);
    
    FVector ActorOrigin, BoxExtent;
    if ((NewBackgroundPos - BoxExtent.X) >
        CamManager->GetCameraLocation().X - (CamManager->GetOrthoWidth() / 2)) {
    
      UE_LOG(LogParallax, Warning, TEXT("Background %d LeftBorder! need spawning"), Index);
    }

This seems to be true, but I'm missing something else, perhaps a scale. (But box extent changes correctly) For some reason, the condition is triggered already on the blue line. And this is true for all backgrounds. Somewhere earlier, somewhere later, but player can always see that the background is over. Maybe it's the orthographic width of the camera? Now it's 2048.

If I am wrong, please tell me how to do it correctly? Thank you. enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.