Add a length parameter to "ViewportPointToRay" and "ScreenPointToRay"

Currently the ViewportPointToRay and ScreenPointToRay APIs return a unit Ray. This is undesirable as you must create a second ray afterwards to manually lengthen it. The wiki includes an example on how to write a wrapper for this, as you’re likely going to need to do it every time you use this API (unless you’re trying to Raycast towards objects within 1 stud of the camera):

local camera = workspace.CurrentCamera
local length = 500
local unitRay = camera:ScreenPointToRay(100, 100)
local ray = Ray.new(unitRay.Origin, unitRay.Direction * length)

I propose adding a 4th length parameter to these methods, which would save developers from having to rewrite this code each time / implement a wrapper.

Camera:ScreenPointToRay(x, y, depth, length)

Camera:ViewportPointToRay(x, y, depth, length)

16 Likes