Issue with converting this vector relative to my HRP's Cframe?

Very stumped on this, I have a vector3 position as the origin of my raycast, the issue with this is that it rotates relative to the world? I think?

I get this behaviour anyways:

The code for this result was this:

	local x = hrp.Position.X + hrp.Size.X / 2
	local z = hrp.Position.Z + hrp.Size.Z / 2
	local _rayResult = raycaster:CastRay(, hrp.Position.Y, z), hrp.CFrame.LookVector, 2, {char}, true)
	rayResult = _rayResult or nil

I then thought I had a breakthrough and used hrp.CFrame:VectorToObjectSpace() on the origin vector however that gave me an even weirder result:

Code for that result:

local x = hrp.Position.X + hrp.Size.X / 2
	local z = hrp.Position.Z + hrp.Size.Z / 2
	local _rayResult = raycaster:CastRay(hrp.CFrame:VectorToObjectSpace(, hrp.Position.Y, z)), hrp.CFrame.LookVector, 2, {char}, true)
	rayResult = _rayResult or nil

If you’re raycasting in the direction of the HRP, then just use the LookVector and multiply it by the length in studs:

local ray = workspace:Raycast(HRP.Position, HRP.CFrame.LookVector * length)

It’s hard to see what’s wrong if you don’t give us the CastRay source code.

Cast ray just uses world root raycast, it just has an added visualizer.

local RayCaster = {}

local raycastParams =
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

-- Ensure that OriginPosition is a vector 3, rayDirection is a unit Vector and rayLength is an integer to multiply the direction by
function RayCaster:CastRay(originPosition, rayDirection, rayLength, toFilter, visualizeRay)

    table.insert(toFilter, workspace.visualizedRays)
    raycastParams.FilterDescendantsInstances = toFilter
    local rayResult = workspace:Raycast(originPosition, rayDirection * rayLength, raycastParams)

    local rayIntersectionPos = rayResult and rayResult.Position or (originPosition + rayDirection * rayLength)

    if visualizeRay then
        local dist = (originPosition - rayIntersectionPos).magnitude
        local part ="Part")
        part.Parent = workspace.visualizedRays
        part.CanCollide = false
        part.Size =, 0.02, dist)
        part.Material = Enum.Material.Neon
        part.Anchored = true
        part.BrickColor = rayResult == nil and"Bright red") or"Bright green")
        part.CFrame = CFrame.lookAt(originPosition, originPosition + rayDirection) *, 0, -dist / 2)
        game:GetService("Debris"):AddItem(part, 0.01)

    return rayResult


return RayCaster

If I’m thinking about what you’re doing correctly then I’m assuming you want to cast the ray near the player’s right arm (like a weapon or tool). You can utilize the -UpVector (Downvector) and RightVector:

local origin = hrp.Position - hrp.CFrame.UpVector * 2 + hrp.CFrame.RightVector * 2