Raycast not detecting projectiles

i have npcs which i want to be able to detect projectiles and know what direction the projectile is coming in.
so i set up 4 raycast on the npcs. (front,back,right,left). all the raycast are fine with detecting when a player moves in front of them. but when it comes to projectiles it doesnt detect it at all.

is the anything else about raycast that i dont know and isnt pointed out on the wiki(no surprise there)

do you know how i cant get them to detect the projectile. or any other detection method i can use. here it my code

local c = NPC.Character
			local r = c.HumanoidRootPart
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {c}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			local HB = game:GetService("RunService").Heartbeat:Connect(function(dt)
				local FrontRay = workspace:Raycast(r.Position, r.CFrame.LookVector * 50, raycastParams)
				local BackRay = workspace:Raycast(r.Position, -r.CFrame.LookVector * 50, raycastParams)
				local RightRay = workspace:Raycast(r.Position, r.CFrame.RightVector * 50, raycastParams)
				local leftRay = workspace:Raycast(r.Position, -r.CFrame.RightVector * 50, raycastParams)
				if FrontRay then
					print("Projtile Infront")
					Soul.Dashing(NPC,4)
				end
				if BackRay then
					print("Projectile Behind")
					Soul.Dashing(NPC,3)
				end
				
			end)
1 Like

A raycast is in a straight line. Is the Projectile coming at an angle to the NPC?

should it matter? its a projectile of a fireball being shot

But a ray is just a line, not a cone shape. If you shoot a ray in the LookVector from the HumanoidRootPart it just fires a single ray in a straight line in that direction. With your script if the projectile isn’t directly ahead, behind, left or right of the NPC it won’t hit the projectile.

If the projectile comes in at a 45 degree angle it may never get hit by any of the 4 rays you are using.

Check out this tutorial: Intro to Raycasting

Maybe you should change the script to check for projectiles a Magnitude of 50 studs away using Player:DistanceFromCharacter.