Strange Raycast bug?

I have a Chase AI that I wrote a couple years ago, and it has worked seamlessly for years with no bugs
I do need to mention the AI was originally made on a custom rig, not a default R6 or R15 one
It’s basically just supposed to activate the chase code when a player is spotted/in the line of sight of the model
This bug doesn’t happen with the original rig the AI was modeled off of
The problem is, is that the raycast is messed up for all my models I use it for
It seems to only see the player when the player is on the AI’s right or left side, or when the AI is on the player’s right or left side, and I don’t understand why? All help is appreciated
Also, I’ve looked all over the dev hub for solutions, and they all either give out errors, or the bug is unchanged

Here’s the code
(The code is much larger, this is just the raycasting part)
local SightRay=Ray.new(AI:FindFirstChild(“HumanoidRootPart”).CFrame.Position,(FoundTarget.CFrame.Position-AI:FindFirstChild(“HumanoidRootPart”).CFrame.Position).Unit*128);
local Hit,EndPoint=Game.Workspace:FindPartOnRayWithIgnoreList(SightRay,{AI});

Sorry if the fix is simple, I haven’t attempted to use this code in a little bit

2 Likes

This Raycast code is deprecated and migration to the new Raycast code is highly recommended.
For example, this code can be written as:

--// Creating RaycastParams
local RayParams = RaycastParams.new()
RayParams.RespectCanCollide = true
RayParams.IgnoreWater = true
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {AI}

--// Origin and Direction (inside your ray cast function)
local Origin = AI:GetPivot().Position
local Direction = (PlayerCharacter:GetPivot().Position - AI:GetPivot().Position).Unit

--// Returns a `RaycastResult` (still inside your ray cast function)
local Result = workspace:Raycast(Origin, Direction * 128, RayParams)

Documentation:

RaycastParams, RaycastResult and Raycasting

Alright, I will try this
Thank youu :slight_smile:

1 Like

Okay this actually worked, thank you so much!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.