I have made bounding box, to limit curos movement to certain area of screen, like this:
ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(GetOwningPlayerController()->Player);
if (LocalPlayer)
{
FViewport* Viewport = LocalPlayer->ViewportClient->Viewport;
//FVector2D ViewportSize = GEngine->GameViewport->Viewport->GetSizeXY();
FVector2D MouseMaxTopLeft;
FVector2D MouseMaxBottomRight;
FVector2D MousePos;
GetOwningPlayerController()->GetMousePosition(MousePos.X, MousePos.Y);
MouseMaxTopLeft.X = (Canvas->ClipX * 0.5f - 40.0f)-100;
MouseMaxTopLeft.Y = (Canvas->ClipY * 0.5f + 56.0f)-100;
MouseMaxBottomRight.X = (Canvas->ClipX * 0.5f - 40.0f) + 100;
MouseMaxBottomRight.Y = (Canvas->ClipY * 0.5f + 56.0f) + 100;
DrawRect(FLinearColor::Red, (Canvas->ClipX * 0.5f - 40.0f), (Canvas->ClipY * 0.5f + 56.0f),
100, 100
);
if (MousePos.X > MouseMaxBottomRight.X)
{
Viewport->SetMouse(700, MousePos.Y);
GetOwningPlayerController()->AddYawInput(1);
GEngine->AddOnScreenDebugMessage(1, 10, FColor::Cyan, FString("Mouse Reached X bound"));
}
else if (MousePos.X < MouseMaxTopLeft.X)
{
GetOwningPlayerController()->AddYawInput(-1);
Viewport->SetMouse(500, MousePos.Y);
}
}
Now. It does work. But when cursor reached border, character stop rotating.
So I added these:
GetOwningPlayerController()->AddYawInput(1);
GetOwningPlayerController()->AddYawInput(-1);
And now character rotates. But at const rate, which is less than ideal.
What I’d like to have is limited cursor (corsshair in that case) movement to certain box extends, and at the same time retain fine grain mouse control over character ? It’s certainly somehow possible since other games, do so, but how do I do it in Unreal ?