TBH I’m getting pretty frustrated with this forum - I’ve posted here over and over again multiple different questions and they only ever get 20 views and 0 answers… What’s the point? I feel like I’m wasting my time here
THE QUESTION:
I tried getting world position of the center of the screen then getting the world position of the center again after moving and using that as distance for my screen widget movement calc, but it’s very inconsistent.
I need just the raw screen movement delta for x & y.
I’m at a loss and can’t find any discussions on it.
Thanks in advance!
You could just calculate it manually in your HUD::DrawHUD() function, which is essentially Tick() for HUD.
Here’s a function from our BaseHUD class which extends Unreal’s AHUD. These vars will let you calculate mouse delta.
// in .h file
// Half-width of the viewport this frame.
FIntPoint _viewportCenter;
// Size of the viewport this frame.
FIntPoint _viewportSize;
// Mouse position last frame.
FVector2D _previousMousePosition;
// Mouse position this frame.
FVector2D _mousePosition;
// in .cpp file
void ABaseHUD::UpdateViewportProperties()
{
if (GetWorld())
{
// get viewport size
FIntPoint size = GetWorld()->GetGameViewport()->Viewport->GetSizeXY();
_viewportSize.X = size.X;
_viewportSize.Y = size.Y;
// update viewport center
_viewportCenter.X = _viewportSize.X / 2;
_viewportCenter.Y = _viewportSize.Y / 2;
// update mouse position
_previousMousePosition = _mousePosition;
GetWorld()->GetGameViewport()->GetMousePosition(_mousePosition);
// calc your deltas
}
}