So I’m working on a game with a fixed camera that will begin to side scroll once the player pawn, rather than the mouse, begins pushing against the edge of the screen. I’ve been having a tough time with this one for a few days now - I’ve explored different options like APlayerController::DeprojectScreenPositionToWorld. I’m facing two main challenges based on what I’m seeing in my implementation vs. what I’m finding for resources online:
- I’m getting values out of DeprojectScreenPositionToWorld that I did not expect.
- My game allows the fixed camera to zoom in and out, and the pitch adjusts based on how close or far the camera is from the player.
The behavior I’m hoping to see is that when the pawn reaches the left side of the viewport, the camera will begin moving in the same direction as the player left. The challenge with #2 above is that the left edge of the screen at the bottom of the viewport has an X value lower than at the top because of the camera pitch. The challenge with #1 is that the X value of the screen position I’m returning is closer to the center of the screen than anything by the left side of the viewport. My understanding was that if I deprojected screen position to world from a X and Y of 0, it would return the position based on the top-left corner of the viewport, but instead it’s the bottom center.
Probably worth calling out that my camera is also about 50 points higher on the Z axis than the player. Here is the code I currently have written for the function - any help I could get on this would be massively appreciated:
void ASelector::DetermineScrollLock()
{
int32 ScreenSizeX;
int32 ScreenSizeY;
FVector WorldPosition;
FVector WorldDirection;
// Get current screen size in integer values for X and Y.
PlayerController->GetViewportSize(ScreenSizeX, ScreenSizeY);
// Determine check for left side of screen.
PlayerController->DeprojectScreenPositionToWorld(0, 0, WorldPosition, WorldDirection);
if (this->GetActorLocation().X <= WorldPosition.X)
{
RightScrollLock = true;
}
UE_LOG(LogTemp, Warning, TEXT("Player Location: %f"), this->GetActorLocation().X);
UE_LOG(LogTemp, Warning, TEXT("Player Location: %f"), this->GetActorLocation().Y);
UE_LOG(LogTemp, Warning, TEXT("Projected World Location (X): %f"), WorldPosition.X);
UE_LOG(LogTemp, Warning, TEXT("Projected World Location (Y): %f"), WorldPosition.Y);
}