I have a frame acting as the players crosshair, and I wanna get the same result as a Mouse.Hit.Position but with a frame instead.
Heres what I’ve got:
function crosshairPosition()
local RAY_DISTANCE = 1000
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {character}
local crosshairPos = {crosshairFrame.Position.X.Offset, crosshairFrame.Position.Y.Offset}
local viewportMouseRay = currentCamera:ViewportPointToRay(crosshairPos[1], crosshairPos[2])
local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * (RAY_DISTANCE), raycastParams)
local hitPosition
if rayCastResult then
hitPosition = rayCastResult.Position
end
return hitPosition
end
I added a print to my script and this is what I get:
Top is the frame method and the bottom is Mouse.Hit
My problem is that its not the exact same, please help.