ScreenPointToRay; using my char.head position as origin causes issues

I’m trying to cast a ray that goes from the player’s head, to a position on the screen. (This is not the exact mouse position, this is the mouse position with an offset.)

I figured getting the direction to raycast using ScreenPointToRay, and whilst this works, it’s only precisely going where I set it to go when I set the origin of the ray to the Origin of the ScreenPointToRay, like so:

local raycastResult = workspace:Raycast(UnitRay.Origin, UnitRay.Direction * 999, raycastParams)

However, the issue with this is I believe it’s casting from the camera, which is not what I want, I want it to cast from the player’s head to said position on the screen.

function Shoot()
	local Char = Player.Character

	local raycastParams =
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.IgnoreWater = true
	raycastParams.FilterDescendantsInstances = {workspace.Ignore, Player.Character}

	local UnitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)
	local raycastResult = workspace:Raycast(UnitRay.Origin, UnitRay.Direction * 999, raycastParams)
	if raycastResult then
		local part ="Part", workspace.Ignore)
		part.Position = raycastResult.Position
		part.Anchored = true
		part.Size =,0.1,0.1)

Here’s what I tried additionally:

local raycastResult = workspace:Raycast(Char.Head.Position, (UnitRay.Direction - UnitRay.Origin) * 999, raycastParams)
--No idea where this ray ends up.

local raycastResult = workspace:Raycast(Char.Head.Position, UnitRay.Direction * 999, raycastParams)
--Ends up offset from where it should be

There’s not just a screen floating in space, really.

You’ll have to tell ScreenPointToRay how far away you want the origin to be from the camera by giving it a third argument.

Not sure what exactly you need, but 1 stud will probably work.