Convert World Location To Screen Location is offset

Hey people, I’ve set up these nodes in order to make a crosshair point follow my mouse:


This is a little function I use to feed the ScreenCoords to my widget:

Yet the result is this, the crosshair is offset diagonally according to the mouse cursor.
(The cursor is where the X is, I couldn’t capture it)
image
Thanks for any help :slight_smile:

You’re mixing up 3d projection with 2d. You should be able to just:

image

I did try this one before and tired it again. The result is the same except this time, the distance between the actual cursor and the widget varies as I move the mouse around.

Hey people, I’ve set up these nodes in order to make a crosshair point follow my mouse:

How is this supposed to work? Are we tracing something in the world? Is this why you’re getting projection involved? Asking as I do not not understand the intent. The mouse is not in 3d world. You can project it using direction from the camera and the then convert back to 2d but I don’t think that’s what is needed.


If you’re doing this full screen, you might be able to get away with:

What’s important here is also how the widget is anchored:

image


Another way:

Keep the canvas Visible so we have something to move over. This should work for any window size but may not work when you resize the window run-time.

edit: offset, so the widget is in the very centre. updated the 1st image, too.

1 Like

Actually yes, I’ve only used the mouse example to make the situation easier to understand.
I have this canon’s turret that’s supposed to aim towards a certain world location, I tried to do so using these node. (the line trace is only for debugging).

This is what I use to get the screen coords:
image

This is the result even after fixing the anchors:

I’m gonna be trying the possible solutions you’ve suggested in the morning but I just wanted to provide more context before I go.
Thanks for your time!

1 Like

I see. So what I posted above will make little sense.

If we’re using the mouse to aim and the turret points where the mouse traces into the world::

Do note that you may not need the canvas for this at all (one less widget to worry about). You can position a widget in the viewport directly. But a canvas may be useful for other things, of course.


  • or do we rotate the turret and it then aims along the barrel’s forward?
1 Like

Hey again, sorry for the late response.
I’ve tried everything you’ve posted but unfortunately nothing worked.

  • or do we rotate the turret and it then aims along the barrel’s forward?

This is indeed the involved mechanic, the mouse has nothing to do with it except for controlling the rotation of the turret.

I’ve just found the solution accidentally and I don’t know why it works lol.
I only had to switch this node:
image
With this one:
image
This way I’d be forced to make the crosshair a widget of it’s own instead of merging it with the ui widget but I couldn’t find another option.
Thanks a lot tough :slight_smile:

2 Likes

There is canvas position to account for. That’s what I mentioned under the last pic. This can be made work both ways.

image

Easier to work with than screen position in some (this) cases.

1 Like

I did try this one again but resulted in the same outcome.

image

The approach I accidentally found works to some degree but there is a slightly annoying bug and I’d be grateful if you have any remarks.
Basically, my crosshair image is 10x10 but as I move the mouse around, the aspect ratio of the image also changes. Sometimes it’s 8x10 and sometimes its 8x8, 12x8…
I tried putting inside a SizeBox but that didn’t work either.

It’s a 2d image, how can it be? How are you testing this? Are you adjusting the image size, render scale? Is it wrapped in a scale box? One generally sets the size and that’s it:

image

Is there anything interesting in the widget hierarchy?

I’ve set the crosshair size to be printed out every frame and it indeed remains 10x10 the entire time, but to the eye, it looks like it does.
It’s hard to notice but It’s there: (ignore the color distortion, it’s just a bug in my gif generator)
ddd

This is the widget’s hierarchy:
image

Unrelated but you can get rid of the canvas, you do not need it if you set the position in viewport directly.

Can you test it full screen? Play in Viewport and hit F11. It seems like it’s purely pixel shift / crawl.

Excuse my stupidity but I tried it before and this is what I get:
image
Should I set the entire widget to only take up 10x10 instead of 1920x1080? How do I do it?

Nah, it’s fine. It’s preview. To get more accurate representation:

image

image

The above does not change anything - but instead demonstrates how a widget would look like if its dimensions were 10x10. Quick way to iterate through layouts. Otherwise the editor defaults by stretching that red blob full screen and 16:9 ratio.

And then:

If you want a 10x10 image in 1920x1080 but the viewport is only 1280x720, the 10x10 image will get smaller than 100px in total. We can’t have half or a fraction of a pixel as you scale down so things get fuzzy.

There’s a bunch of features to account for resolution / aspect ratio. Long story:

1 Like

The issue persists even in 1920x1080 fullscreen, I’ll just move on from this. Thanks a ton!

1 Like