What is the best way to create bullet detection?

yes that would be very helpful

local LookRay = Ray.new(Bullet.Position, Bullet.CFrame.lookVector + Vector3.new(0.2,0.2,0.2))
		local LookRay2 = Ray.new(Bullet.Position, -Bullet.CFrame.lookVector + Vector3.new(0.2,0.2,0.2))
		local SideRay = Ray.new(Bullet.Position, Bullet.CFrame.RightVector + Vector3.new(0.2,0.2,0.2))
		local SidekRay2 = Ray.new(Bullet.Position, -Bullet.CFrame.RightVector + Vector3.new(0.2,0.2,0.2))
		local UpRay = Ray.new(Bullet.Position, Bullet.CFrame.UpVector + Vector3.new(0.2,0.2,0.2))
		local UpRay2 = Ray.new(Bullet.Position, -Bullet.CFrame.UpVector + Vector3.new(0.2,0.2,0.2))
		local Rays = {
			LookRay;
			LookRay2;
			SideRay;
			SidekRay2;
			UpRay;
			UpRay2;
			}

while true do
			wait(0.001)
			for i,SelectedRay in pairs(Rays) do
				local hit, pos = workspace:FindPartOnRay(SelectedRay)
				if hit then
					
					print("Found not you lol")
					Bullet:Destroy()
					print(hit.Parent.Name)
					if hit.Parent:FindFirstChildOfClass("Humanoid") and Landed == false then
						Landed = true
						hit.Parent:FindFirstChildOfClass("Humanoid").Health = hit.Parent:FindFirstChildOfClass("Humanoid").Health - SettingsModule.Damage
						print("Bullet gone")
						break
					end
				end
				

			end
			
		end

This is one of my older ways I did it

Another way I tried was by doing them one by one with these

local HF, PF = workspace:FindPartOnRay(FrontRay);
			local HB, PB = workspace:FindPartOnRay(BackRay);
			local HR, PR = workspace:FindPartOnRay(RightRay);
			local HL, PL = workspace:FindPartOnRay(LeftRay);
			local HU, PU = workspace:FindPartOnRay(UpRay);
			local HD, PD = workspace:FindPartOnRay(DownRay);

this is interesting, are you firing rays when you click a mousebutton? and where are the bullets located, is there a gun?

Yes it’s an automatic weapon so when I hold down my mouse it shoots where the mouse is with little spread. I parent the bullets into a folder named “Debris” inside of workspace

ray.new(origin,direction)

you set the direction to only 0.2 studs , which is a very short number, is this intentional?

I sent it to add with the Vectors of the bullet which I guess yeah is only 0.2 studs so yes it was intentional but I couldn’t figure out a good size

Also here is a video of it

when you aim at the dummy from that distance, does it actually hit?

Theres usually a little gap between the dummy and the bullet sometimes it does damage and sometimes not

one problem i see is
Ray.new(Bullet.Position, -Bullet.CFrame.UpVector + Vector3.new(0.2,0.2,0.2))
you specified a origin and a direction, but your direction is literally only 0.2 studs long, multiply it with the amount of studs you want your ray to travel

Ray.new(Bullet.Position, (-Bullet.CFrame.UpVector + Vector3.new(0.2,0.2,0.2))*RANGE)

Interesting!
Ill try it give me a minute to rewrite the Cast

also the most important thing i just noticed, you are launching the bullets at the enemy and then casting a ray to see if it touched right?

Yes it’s launching to my mouse and checking simultaneously

oh my bruhness this is such a bruh moment

1 Like

games like counterstrike and other FIRST PERSON shooters cast a ray from the center of the players screen to the crosshair, but in third person like yours, you would need to cast a ray from your guns barrel to where your cursor is.

bullet detection and bullet visualization should be seperate systems

So you mean like newRay = Ray.new(Barrel.Position, Mouse)
?
Btw Mouse is Mouse.Hit.p coming from a local script

tbh I forgot that a ray stops when it finds something ( I think)

yeah in your old system, youre launching a bullet from and then ray casting in a direction, ur bullets might spasm and face in a unwanted direction

Gotchu Ill remake it and update you on how it goes Thanks

You’ll probably want to use workspace:Raycast in the new system, FindPartOnRay is deprecated

2 Likes