I’m having an issue with raycasting simply going through the character that I’m trying to register. This wouldn’t be a problem if I wasn’t bug-fixing a gun system, but I am.
This is an example of the issue. The beam is located between the starting point (Barrel), and the raycast endpoint.
Could we see the code please? It’s hard to find a definitive issue with your code if I can’t see it.
Yes, of course. This is the module code that handles that:
function GDH:rayCast(start, direction, range, ignore)
local RaycastParameters = RaycastParams.new();RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist; RaycastParameters.FilterDescendantsInstances = {ignore}
local RayCastResult = workspace:Raycast(start, direction * range, RaycastParameters)
local hit = RayCastResult.Instance
local endPos = RayCastResult.Position
if hit and (hit.Transparency > 0.75
or hit.Name == "Handle"
or (hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health == 0)) then
hit, endPos = self:rayCast(endPos + (direction * 0.01), direction, range - ((start - endPos).magnitude), ignore)
end
return hit, endPos
end
From what I see, I think it may be the parameters you’re inputting that’d be the problem. Are you possibly passing the enemy through the ignore list?
Also, I forgot to mention but on this line
hit, endPos = self:rayCast(endPos + (direction * 0.01), direction, range - ((start - endPos).magnitude), ignore)
should it not be direction * range - ((start - endPos).magnitude)?
I am not, no. I’m passing the character model of the player who fired the weapon.
Most of the math written in here was written by someone with quite a bit more knowledge about it than me, I will be sure to ask him though.
Disregard what I said, I forgot it was its own function, and not the actual roblox RayCast one, which takes 3 arguments.
Does the hit variable return as nil if you shoot the humanoid? Could be a misplaced debug.
No it does not. It returns the shit behind the player. Baseplate, tree, another player xD
its because the humanoid root part is semi transparent and thus, is registering for the check if a part is above 0.75 transparency
Thank you. I would have never figured that out myself xD