I’m trying to work with rays for my enemies however they seem to be a big um buggy they shoot upwards and with the 4th dummy they’re just shooting backwards lol thought it should go towards the players rootpart?
This is the code I use to make the rays visible
local radius = 0.1
local function MakeRayVisible(ray)
local MidPoint = ray.Origin + ray.Direction/2
local Part = Instance.new("Part")
Part.Parent = workspace
Part.Anchored = true
Part.CanCollide = false
Part.CFrame = CFrame.new(MidPoint,ray.Origin)
Part.Size = Vector3.new(radius,radius,ray.Direction.magnitude)
Part.Material = "Neon"
Part.Color = Color3.fromRGB(170, 0, 0)
return Part
end
And this is the code I have for making the ray and stuff
while true do
for EnemyName,EnemyInfo in pairs(Enemies) do
if EnemyFolder:FindFirstChild(EnemyName) then
--print("Enemy Found",EnemyName)
local EnemyCharacter = EnemyFolder:FindFirstChild(EnemyName)
local EnemeyCharacterHMR = EnemyCharacter.HumanoidRootPart
local TargetHMR = NearestPlayer(EnemeyCharacterHMR.Position)
if TargetHMR then
--print("Target Found",TargetHMR.Parent.Name)
local ray = Ray.new(EnemeyCharacterHMR.Position,TargetHMR.Position)
local Part = workspace:FindPartOnRay(ray,TargetHMR)
MakeRayVisible(ray)
if Part ~= nil then
print(Part)
end
--[[
if Part ~= nil then
print(Part)
print("Part",Part.Parent.Humanoid)
if Part.Parent:FindFirstChild("Humanoid") then
print("Humanoid")
Guns[EnemyInfo.Gun](TargetHMR,EnemyCharacter)
else
print("No Humanoid")
end
else
print("No Part",EnemeyCharacterHMR.Parent.Name)
print(Part)
end
]]
end
end
end
wait(1)
end