Modifying the Screen To World Space node

Modifying the Screen To World Space node:

  1. Fixed the bug indicated here and here. The solution was used from here.
  2. Added output parameter Direction (normalized vector).
  3. Added option to split output vectors into components.
    screen_to_world

Scripts: ScreenToWorldSpaceNode.zip
Demo: web-version.
Demo 2: web-version.

2 Likes

Awesome!

However I’m not sure if it works 100% correctly.
When my mouse is directly over the target, the balls miss (the difference is bigger when further away from the center):
screenToWorld

But this might be an issue with the demo or the browser or whatever and not the logic node itself.

I multiplied by the vector and corrected its values to make it more interesting to play. But the demonstration failed as a result.

This one will be clearer: demo2.

1 Like

I would suggest another layout to this node considering its usability:

Two integer inputs (X and Y) – mouse and its coordinates nodes are not more a “vector”, but a separated vector.

The output is better to be X and Y floats to avoid confusion, because the Y coordinate may be commonly applied to a Z coordinate in 3D space object or whatever.

The same can go to World To Screen Space and UI nodes, but we can think about it later

Output parameters are of type Vector or Float. I don’t understand what you mean.

I agree, it will be more convenient.

Like this:

I don’t know what exactly is the Direction Output, then i don’t know if it is better separated or as a Vector.

Using 2D vectors separated will avoid users getting null values, but we need to keep the same for all nodes like this one, as for UI nodes, etc.

World coordinates are points in 3D space that have all three coordinates. For World, the Z value will be equal to the Z value of the camera.
Direction is a vector that goes from the camera position in the direction the cursor is pointing. For the second demo, I just took this vector, multiplied it by the velocity and assigned it to the object via Set RB Velocity.
The user will never get null.

1 Like

New version logic node:
screen_to_world_v2

Input parameters:

  • Screen X - value of screen coordinates along the X axis (data type Int);
  • Screen Y - the value of the screen coordinates along the Y axis (data type Int).

Options:

  • Separator Out - whether or not to separate the output parameters (vectors) into components (XYZ).

Output parameters:

  • World - coordinates of a point in 3D space (Vector data type)
  • Direction - normalized direction vector from the camera towards the point/cursor indication (data type Vector).
  • X, Y, Z - components of the corresponding vectors (data type Float).

Scripts: ScreenToWorldSpaceNode.zip

2 Likes