I’m a UE4 novice, and have started to learn by creating an “Asteroids” type game.
I’m creating an actor with a CameraComponent:
UCLASS()
class ASTEROIDS_API AMyGameCamera : public AActor
{
GENERATED_BODY()
......
protected:
UPROPERTY(VisibleAnywhere, Category = "Components")
UCameraComponent* GameCameraComp;
};
And setting it up in the constructor thusly:
AMyGameCamera::AMyGameCamera()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
GameCameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCameraComp"));
GameCameraComp->SetProjectionMode(ECameraProjectionMode::Orthographic);
GameCameraComp->SetOrthoWidth(2048.0f);
// Origin (0,0,0).
// Set the camera facing down, so that right & down on screen == +XY respectively!
SetActorLocation(FVector(0.0f, 0.0f, 2000.0f));
SetActorRotation(FRotator(-90.0f, -90.0f, 0.0f));
GameCameraComp->SetupAttachment(RootComponent);
}
To get the play area from this camera I’m getting the OrthoWidth and scaling that by the cameras AspectRatio:
FVector2D Result;
Result.X = GameCameraComp->OrthoWidth;
Result.Y = Result.X / GameCameraComp->AspectRatio;
But it’s not correct, the X (since it’s a parameter) is spot on, but the Y is much larger than it should be, hence my “wrap” function of the the ship has some considerable overlap in the Y axis during play.
Clearly, I’m missing something (that’s probably obvious)…
Does anyone know how to calculate an accurate play area from an orthographic camera?