Hello there.
I’m currently working on this little system of mine, when I noticed that the raycasts are producing inaccurate results.
After looking into it I narrowed down the cause of it to the direction the raycast is firing in. After creating parts to see where the raycast is being fired too, it turns out the direction is based on where the player originally was?
For context I am trying to fire a raycast about 50 studs out in front of the player, I tested this by spinning in a circle, and it works fine when I do it without walking around at all, but the second I start moving away from where I spawned I started noticing something wasnt right.
Example:
After spinning in a circle whilst the raycats were firing, I can see that they were all fired around spawn?? The blue blocks is where it fired too, and the red blocks are where it fired from, aka where I am.
I have no idea what the issue is, so I’ve come here!
Here is some of my code!
Raycast code
function Class:RaycastInDirection(position:Vector3, direction:Vector3, Filter:HitboxFilter, ActionName:string) : (BasePart, Vector3)
-- // Params
local Params:RaycastParams
if ActionName and Class._Params[ActionName] then
Params = Class._Params[ActionName]
else
Params = RaycastParams.new()
end
Params.FilterDescendantsInstances = OOPLibrary:CombineTables(Filter:GetFilterInstances(), GetIgnore())
-- // Raycast
local Result = workspace:Raycast(position, direction, Params)
if not Result or not Result.Instance then
-- // Debug
Class:NewDebugBox(CFrame.new(position))
Class:NewDebugBox(CFrame.new(direction), nil, Color3.fromRGB(0,1,0))
print('Make Part:', direction)
end
if not Result or not Result.Instance then return nil end
-- // Get Target
local Target = Result.Instance
if Target:FindFirstAncestorOfClass('Model') then
Target = Target:FindFirstAncestorOfClass('Model').PrimaryPart or Target
end
-- // Finish Up
return Target, Result.Position
end
Code that triggers the function
local Target:BasePart, TargetPosition = HitboxModule:RaycastInDirection(
Root.CFrame.Position,
Root.CFrame.LookVector * 50,
CharacterFilter
)
PS Root is the HumanoidRootPart of the character.
Any idea whats going on? Thanks in advance!
