In this video, my raycasting doesn’t seem to work properly on an actual player but it works perfectly in studios on an NPC. On the front face of the player, the raycast just seems to ignore the player unless if I get really close to the player, but the backside of the player, the raycast works perfectly fine.
Here is the line of code of the raycast trimmed up for simplicity:
for i , v in pairs(CollectionService:GetTagged("Targetable")) do
local EnemyRootPart = ...
local Distance = EnemyRootPart.Position - MyHumRootPart.Position
if Distance.Magnitude < ClosestRange then -- Within Distance
ClosestRange = Distance.Magnitude
local RayCast = Ray.new(MyHumRootPart.Position,Distance.Unit * 500)
local Hit, HitPosition = workspace:FindPartOnRayWithIgnoreList(RayCast, {Character}) -- Ignore Self But Cast Ray
local FaceofMyCharacter = Distance.Unit -- Unit Converts Numbers to Vector3
local HeadLook = Character.Head.CFrame.LookVector
-- Gets the Orientation from 1 to the players Look Direction to -1 Behind Head
local DotProduct = FaceofMyCharacter:Dot(HeadLook)
if Hit:IsDescendantOf(v) and DotProduct >= Accuracy then
Target = EnemyRootPart -- Enemy Marked
end
end
end
Now I know this is the old raycasting method, but it should still work properly with raycasting the target. I did try the new raycasting method with no success. I don’t know what I did wrong with the new raycasting, but I struggle to implement the new method into my script. Still, the old raycasting should work just as well.