Skip to content

Commit c965075

Browse files
committed
Also update Camera.ViewportPointToRay
1 parent c178880 commit c965075

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed
Lines changed: 3 additions & 0 deletions
Loading

content/en-us/reference/engine/classes/Camera.yaml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,20 +1175,24 @@ methods:
11751175
summary: |
11761176
Creates a unit `Datatype.Ray` from a position on the viewport (in pixels),
11771177
at a given depth from the `Class.Camera`, orientated in the camera's
1178-
direction. Does not account for the GUI inset.
1178+
direction. Does not account for the Core UI inset.
11791179
description: |
1180-
This function creates a unit `Datatype.Ray` from a 2D position on the
1181-
viewport (defined in pixels). This position does **not** account for the
1182-
GUI inset. The `Datatype.Ray` originates from the `Datatype.Vector3`
1183-
equivalent of the 2D position in the world at the given depth (in studs)
1184-
away from the `Class.Camera`.
1185-
1186-
As this function does not acknowledge the GUI inset, the viewport position
1187-
given is not equivalent to the screen position used by GUI elements. If
1188-
you are not using `Class.ScreenGui.IgnoreGuiInset` and need an otherwise
1189-
identical function that accounts for the GUI offset, use
1180+
This function creates a unit `Datatype.Ray` from a 2D position in device safe viewport coordinates (defined in pixels). That is, `(0, 0)` corresponds to the top left point of the Roblox top bar.
1181+
1182+
<img src="/assets/engine-api/classes/Camera/DeviceSafeViewportCoordinates.jpg" width="720" alt="Diagram showing the origin of the device safe area viewport coordinate system." />
1183+
1184+
The input 2D position does **not** account for the Core UI inset, but does account for any device safe insets.
1185+
The `Datatype.Ray` originates from the `Datatype.Vector3` equivalent of the 2D position in the world at the given depth (in studs) away from the `Class.Camera`.
1186+
1187+
Note that UI instances use a different coordinate system. `Class.GuiObject.AbsolutePosition` uses the Core UI viewport coordinate system, while this function uses the device safe viewport coordinate system. If you would like to specify position in Core UI coordinates, please use
11901188
`Class.Camera:ScreenPointToRay()`.
11911189
1190+
This function only works for the current Workspace camera. Other cameras,
1191+
such as those you create for a `Class.ViewportFrame`, have an initial
1192+
viewport size of `(1, 1)` and are only updated after you set them to
1193+
`Class.Workspace.CurrentCamera`. The mismatch in viewport size causes the
1194+
camera to return a ray with an incorrect `Datatype.Ray.Direction`.
1195+
11921196
This function can be used in conjunction with the
11931197
`Class.Camera.ViewportSize` property to create a ray from the centre of
11941198
the screen, for example:
@@ -1208,28 +1212,20 @@ methods:
12081212
local unitRay = camera:ScreenPointToRay(100, 100)
12091213
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
12101214
```
1211-
1212-
This function only works for the current Workspace camera. Other cameras,
1213-
such as those you create for a `Class.ViewportFrame`, have an initial
1214-
viewport size of `(1, 1)` and are only updated after you set them to
1215-
`Class.Workspace.CurrentCamera`. The mismatch in viewport size causes the
1216-
camera to return a ray with an incorrect `Datatype.Ray.Direction`.
12171215
code_samples:
12181216
parameters:
12191217
- name: x
12201218
type: float
12211219
default:
12221220
summary: |
12231221
The position on the X axis, in pixels, of the viewport point at which
1224-
to originate the `Datatype.Ray`. This position does not account for
1225-
the GUI inset.
1222+
to originate the `Datatype.Ray`. In device safe area coordinates.
12261223
- name: 'y'
12271224
type: float
12281225
default:
12291226
summary: |
12301227
The position on the Y axis, in pixels, of the viewport point at which
1231-
to originate the `Datatype.Ray`. This position does not account for
1232-
the GUI inset.
1228+
to originate the `Datatype.Ray`. In device safe area coordinates.
12331229
- name: depth
12341230
type: float
12351231
default: 0

0 commit comments

Comments
 (0)