The video below will explain what I’m experiencing. (I’m bad at explaining, ask my teacher if you want)
I’ve rewritten this function at least five times now and have gotten the same results. The current version is from Roblox Battle Royale’s (lol) weapons.
local function SpawnRayCast(StartPos, Direction, Length)
local Hit, EndPos = workspace:FindPartOnRayWithIgnoreList(Ray.new(StartPos,Direction * Length), {Camera, Tool.Parent})
if Hit then
local FirePointObject = VMHandleToFire:FindFirstChild("GunFirePoint")
if FirePointObject ~= nil then
local tipCFrame = FirePointObject.WorldCFrame
local tipPos = tipCFrame.Position
local tipDir = tipCFrame.LookVector
local amountToCheatBack = math.abs((Camera.Arms.Handle.Position - tipPos):Dot(tipDir)) + 1
local gunRay = Ray.new(tipPos - tipDir.Unit * amountToCheatBack, tipDir.Unit * amountToCheatBack)
local hitPart, hitPoint = Roblox.penetrateCast(gunRay, {Camera, Tool.Parent})
if hitPart and math.abs((tipPos - hitPoint).Magnitude) > 0 then
return SpawnRayCast(EndPos + Direction * 0.1, Direction, Length - ((StartPos - EndPos).magnitude))
end
end
end
return EndPos
end
I think it would be important to show us what does the EndPos variable is about. I know it’s mouse location but I wanna make sure. Also, you should use workspace:Raycast and RaycastParamsnew() since I believe the other functions of raycastibg is deprecated.
I think the issue here might be with your use of the Camera:ScreenPointToRay() function, being that it doesn’t account for GuiInset. Had the same problem with my mouse-to-world function. You could try making a debug part and CFraming it to the ray’s raycast result (if you turn it into an actual raycast using workspace:Raycast), which would let you know how the variable is different from expected (if at all).
(sorry for late response) I’ve already tried using debugging part to see if anything was wrong but everything seems to be working fine. Forgot to mention it only does this when shooting through a window and very tight spaces.
It could have something to do with how your windows were designed. Are the window frames one big union? That could be the cause for the raycast stopping at the window.