Screen To World: Difference between revisions

Added examples, adapted "How do I know which object is being tapped?" article from old wiki
(Created page with "Given a screen coordinate, outputs the start and end points of a line going through that point (2 and 400 units away from the camera, respectively). That might sound weird, but usually you'll just wire those points into a Raycast to find the object the user tapped! /uploads/Screen To World.png = Notes = Due to a technical issue, still to be fixed, the output lags by one frame. I.e. if you Set Camera on frame N, then this block's...")
 
(Added examples, adapted "How do I know which object is being tapped?" article from old wiki)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Given a screen coordinate, outputs the start and end points of a line going through that point (2 and 400 units away from the camera, respectively). That might sound weird, but usually you'll just wire those points into a [[Raycast]] to find the object the user tapped!
{{Block
|image=Screen_To_World.png
|type=s
|folder=Math
|input1={{Port|n|Screen X}}
|input2={{Port|n|Screen Y}}
|output1={{Port|v|World Near}}
|output2={{Port|v|World Far}}
}}


[[width=336px,alt=Screen To World|/uploads/Screen To World.png]]
Given a screen coordinate, outputs the start and end points of a line going through that point (2 and 400 units away from the camera, respectively).


= Notes =
That might sound weird, but usually you'll just wire those points into a [[Raycast]] to find the object the user tapped, or [[Line vs Plane]] to find where on the ground the user tapped (see [[Screen To World#Examples|Examples]]).
Due to a technical issue, still to be fixed, the output lags by one frame. I.e. if you Set Camera on frame N, then this block's output will change on frame N+1.


Because of this bug, the script will not work on the first frame. To avoid incorrect values, use the block's output only if the [[Current Frame]] is greater than 0.
== Notes ==


Due to a technical issue, still to be fixed, the output lags by one frame. In other words, if you [[Set Camera]] on frame N, then this block's output will change on frame N+1.
Because of this bug, the script will not function correctly on the first frame. To avoid incorrect values, use the block's output only if the [[Current Frame]] is greater than 0.
== Examples ==
* Find the object the user has tapped by using [[Raycast]].
: {{Image|Tapped object.png}}
* Find the position on the ground the user tapped (and place an object there) by using [[Line vs Plane]].
: {{Image|Line vs plane example1.png}}
== Related ==
* [[World To Screen]]
* [[Screen Size]]


[[Category:Blocks]]
[[Category:Blocks]]