You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en-us/reference/engine/classes/Camera.yaml
+17-21Lines changed: 17 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1175,20 +1175,24 @@ methods:
1175
1175
summary: |
1176
1176
Creates a unit `Datatype.Ray` from a position on the viewport (in pixels),
1177
1177
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.
1179
1179
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
1190
1188
`Class.Camera:ScreenPointToRay()`.
1191
1189
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
+
1192
1196
This function can be used in conjunction with the
1193
1197
`Class.Camera.ViewportSize` property to create a ray from the centre of
1194
1198
the screen, for example:
@@ -1208,28 +1212,20 @@ methods:
1208
1212
local unitRay = camera:ScreenPointToRay(100, 100)
1209
1213
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
1210
1214
```
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`.
1217
1215
code_samples:
1218
1216
parameters:
1219
1217
- name: x
1220
1218
type: float
1221
1219
default:
1222
1220
summary: |
1223
1221
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.
1226
1223
- name: 'y'
1227
1224
type: float
1228
1225
default:
1229
1226
summary: |
1230
1227
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.
0 commit comments