So I am working on a system that should send a raycast from the HRPs position out to the left of the player, now from the look of things, it works, but something strange happens.
So here is my demonstration on what happens;
If I come from the front of the box and the raycast fires, yippie it knows the part is there!
Same with the right side of the object, but when I come from the left or back, it just doesnt trigger.
I’ve checked my params for the raycast, I’ve gone out of the way to display where the raycast is firing too (which it is always in the right place) alas, still, when I come up to that side of the part, it fails.
I have the spawn surrounded by some parts, to demonstrate which sides the raycast is triggering on for them observe ( The sides with green are the sides the raycast does trigger on)
As we can see there is a pattern here, the problem is now what can I do about it?
It seems to be all based on where the position (0,0,0) is, cause if I we’re to move the parts away from that area, the results would change. Overall this is just the most confusing thing I’ve ever had to deal with. Heres my code:
Main Code
OnLeftWall = function(Ignore)
local isTouching,Objects = isTouching()
if isTouching then
local params = getParams(true,Ignore)
local originPo = root.CFrame.Position
local targetCframe = root.CFrame * CFrame.new(-1,0,0)
local targetPo = targetCframe.Position
local po2 = getPO2(CFrame.new(raycastOffsets.Left,0,0),char)
local debugPart:BasePart = createDebugPart(po2,Vector3.new(1,1,1),nil,true)
if debugPart then
debugPart.Color = Color3.new(1, 0.666667, 0)
end
local raycast = workspace:Raycast(originPo,po2,params)
if raycast then
local hit:BasePart = raycast.Instance
print(hit)
end
end
end,
GetParams
PS: I am 100% that the raycast params are not ignoring the parts, I’ve checked over whats being added, and the parts are not getting ignored.
local function getParams(RP,Ignore)
local params = RaycastParams.new()
if not RP then
params = OverlapParams.new()
end
local ignoring = {}
-- || Handle Items to Ignore
if Ignore then
for _, item in Ignore do
table.insert(ignoring,item)
if item:IsA("Instance") then
for _, d in item:GetDescendants() do
table.insert(ignoring,d)
end
end
end
end
-- || Ignore Characters ||
for _, char in workspace:GetDescendants() do
if char:IsA('Model') then
if char:FindFirstChildOfClass('Humanoid') then
table.insert(ignoring,char)
for _, item in char:GetDescendants() do
table.insert(ignoring,item)
end
end
end
end
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = ignoring
return params
end
Get Po2
function getPO2(distance,char)
local part = Instance.new('Part') -- the reason we make a part is cause other wise it will act weird
local po = char.PrimaryPart.CFrame * distance
part.CFrame = po
local po2 = part.Position
part:Destroy()
return po2
end
If you have any questions about anything please do ask me!