Hi everyone, I’m working on a litte game with an RTS like camera, the camera is working, but I have some issue with the edge scrolling
here is my issue :
The only edge scrolling that I have is “Top Left”, no matter which side the mouse is, the camera is scrolling to Top Left
first of all I have a Pawn for a the camera, and an Arm sping attach to an invisible sphere
And I’m detecting the edge scrolling in the Player controller :
void ABTD_PlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
HandleEdgeScrolling();
}
void ABTD_PlayerController::HandleEdgeScrolling()
{
float MouseX = 0.0f;
float MouseY = 0.0f;
if (GetMousePosition(MouseX, MouseY))
return;
int32 SizeX = 0;
int32 SizeY = 0;
GetViewportSize(SizeX, SizeY);
if (MouseX < EdgeScrollingSensitivity) //Mouse is Close to Left
OnCameraRight(-1);
else if (MouseX > SizeX - EdgeScrollingSensitivity) //Mouse is Close to Right
OnCameraRight(1);
if (MouseY < EdgeScrollingSensitivity) //Mouse is Close to Top
OnCameraForward(1);
else if (MouseY > SizeY - EdgeScrollingSensitivity) //Mouse is Close to Bottom
OnCameraForward(-1);
}
void ABTD_PlayerController::OnCameraForward(float Axis)
{
ABTD_PlayerPawn* const MyPawn = Cast<ABTD_PlayerPawn>(GetPawn());
if (MyPawn)
{
FVector NewDeltaLocation = MyPawn->PawnBaseCollsion->GetForwardVector() * (CameraMovementSpeed * Axis);
MyPawn->AddActorWorldOffset(NewDeltaLocation);
}
}
void ABTD_PlayerController::OnCameraRight(float Axis)
{
ABTD_PlayerPawn* const MyPawn = Cast<ABTD_PlayerPawn>(GetPawn());
if (MyPawn)
{
FVector NewDeltaLocation = MyPawn->PawnBaseCollsion->GetRightVector() * (CameraMovementSpeed * Axis);
MyPawn->AddActorWorldOffset(NewDeltaLocation);
}
}
Any Idea what I’m doing wrong here ?