Limiting mouse movement. How to retain fine controll over character rotation ?

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()-&gt;AddYawInput(1);

GetOwningPlayerController()-&gt;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 ?

**Mouse Delta **

Can you do a printout of this, within your function?



FVector2D MouseDelta;
GetOwningPlayerController()->GetInputMouseDelta(MouseDelta.X, MouseDelta.Y);

GEngine->AddOnScreenDebugMessage(1, 10, FColor::Red, MouseDelta.ToString());


As long as you are retaining the mouse delta during your function, and see values ranging from like like -5 to 5 or something like that for x and y, then you can map the mouse deltas to relative character rotations.

Critical first question though is whether you are seeing the mouse deltas continue to change even after you are setting the mouse position.


**Larger Picture**

Is this for some kind of character creation menu?

If you dont need this during gamplay I personally would just rotate the chracter using Q and E or some other keys during this special menu with limited mouse movement.

If you need code for doing this let me know.

Rama

Delta at this point is 0, because mouse is not moving at all.

And this is during game. I want to add some secondary targeting, where you can target without completely rotating your character.

Anyway, another possible solution would to just limit crosshair drawing and allow mouse to move over entire screen. But that’s also will have downside of crosshair loosing synced postion with mouse.