Just trying to add a basic crosshair to a top down shooter game, running on 5.1
this is what I have
what am I doing wrong?
sorry forgot to mention that this is in the widget event graph itself
Just trying to add a basic crosshair to a top down shooter game, running on 5.1
this is what I have
what am I doing wrong?
sorry forgot to mention that this is in the widget event graph itself
ah so I should just wait?
now I’m running into a problem where I have an offset between the actual mouse pointer and the crosshair itself, Maybe I should just shoulder this for right now and move onto other stuff
Try to use GetMousePositionOnViewport:
still doesnt seem to work, appreciate the help though!
Depends what you mean by offset. At the hardware cursor position X0Y0 (top left) the cursor will grow down and to the right. Most likely you mean that your crosshair’s origin is currently that top left but is supposed to be centered. In that case you want the absolute position of the cursor + half the size of the crosshair texture as a negative offset.
Sorry, maybe offset isnt the right word, maybe a parallax is more suitable? Not sure, here’s a video of what I mean
and here is a screenshot of how I have the crosshair setup in my widget designer
Ah, ok, I usually set my cursor widget to the top left anchor and make it use only the space it needs but this should be fine. On the video it looks like the cursor position is retrieved but not translated properly. I’m quite often struggling with this problem myself .
The following should be similar in blueprints, I work in c++.
In my cursor system I first retrieve the widget geometry of the player’s screen:
const FGeometry Geometry = UWidgetLayoutLibrary::GetPlayerScreenWidgetGeometry(GetOwningPlayer());
Then I get the Absolute position of the cursor and translate it to the local coordinates within the geometry. Using those local coordinates, I set the position of a canvas slot. The cursor widget is a child of a canvas panel.:
CanvasSlot->SetPosition(Geometry.AbsoluteToLocal(VCSS->GetCursorPosition()));
So far that works just fine.
Position = FSlateApplication::Get().GetCursorPos();
I believe in blueprints you can access it through the PlayerController.
Sometimes UE is an overcomplicated beast right.
I guess I can try something like this, might take me a minute to find out what each of these are in BP, maybe I will try the C++ approach
Maybe its something with my viewport layout? I tried to keep it very simple
That was the problem, I some how ploinked my anchor, Thank you all so much for your help