Raycast from UI

I’m trying to get all 3D Objects intersecting with a GuiObject (in this instance a mobile cursor) however it is returning nil.

_G._Raycast = function(_range : number, _params)
	_range = _range or 10000
	local _cursor = _G._settings._EasyRaycast and Player.PlayerGui.HUD._mobileCursor  or Player.PlayerGui.HUD._mobileCursor.Frame
	local ray = workspace.CurrentCamera:ScreenPointToRay(_cursor.Position.X.Scale*_cursor.Size.X.Scale, _cursor.Position.Y.Scale*_cursor.Size.Y.Scale, 1)
	local origin = ray.Origin
	local direction = ray.Direction.Unit*_range
	local raycast = workspace:Raycast(origin, direction, _params)
	
	return raycast
end

_cursor.Position.X.Scale*_cursor.Size.X.Scale

Why do you multiply the position scale by the size scale?

Since Camera:ScreenPointToRay expect pixel coordinates to be passed in, wouldn’t it be easier to use _cursor.AbsolutePosition.X and _cursor.AbsolutePosition.Y?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.