Blood Raycast detection

I’m currently working on a script where blood comes out of the character in chunks and is supposed to splatter when it comes into contact with an object (wall,ground) the issue is that the blood only splatters occasionally and usually the chunk just goes straight through the object and the hit detection doesn’t work, sorry if this is hard to understand I suck at explaining things.

here’s the main code:

while true do
wait(math.random(0,0.8))
local blood = game.ServerStorage:WaitForChild(“Meatball”):Clone()
blood.Parent = character.Head

debris:AddItem(blood,1)

if speed > 3 then
	blood.Transparency = 0
	offset = -4.5
else
	blood.Transparency = 0
	offset = 0
end

blood.CFrame = character.Torso.CFrame * CFrame.new(0,1.5,offset)
local bv = Instance.new("BodyVelocity", blood)
bv.MaxForce = Vector3.new(3000,3000,3000)
bv.P = 100  --1000
bv.Velocity = Vector3.new(math.random(-15,30),math.random(-15,30),math.random(-15,30))
wait()
bv.MaxForce = Vector3.new(0,0,0)
bv.P = 0
bv.Velocity = Vector3.new(0,0,0)

local connection

function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") == nil and hit.Parent.Parent:FindFirstChild("Humanoid") == nil then
		blood.Anchored = true
		blood.Transparency = 1
		local dist = math.random(1, 2)

		local rays = {
			rayforward = Ray.new(blood.Position, blood.CFrame.lookVector * dist),
			raybackward = Ray.new(blood.Position, blood.CFrame.lookVector * -dist),
			rayright = Ray.new(blood.Position, blood.CFrame.RightVector * dist),
			rayleft = Ray.new(blood.Position, blood.CFrame.RightVector * -dist),
			raydown = Ray.new(blood.Position, blood.CFrame.UpVector * -dist),
			rayup = Ray.new(blood.Position, blood.CFrame.UpVector * dist)
		}	

		for i,ray in pairs(rays) do
			local hit, pos, normal = game.Workspace:FindPartOnRay(ray, character)

			if hit and hit.Parent:FindFirstChild("Humanoid") == nil and hit.Parent.Parent:FindFirstChild("Humanoid") == nil and hit.Name ~= "Splatter" then
				local splatter = game.ServerStorage.Splatter:GetChildren()[math.random(1,2)]:Clone()
				local dropsize = math.random(dropsizemin * 10,dropsizemax *10) / 10
				splatter.Parent = game.Workspace
				splatter.CFrame = CFrame.new(pos, pos + normal) * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.Angles(0, math.rad(math.random(1, 360)), 0) * CFrame.new(0, 0.04, 0)
				ts:Create(splatter, tweeninfo, {Size = Vector3.new(dropsize, 0.10,dropsize)}):Play()
				debris:AddItem(splatter,5)
			end
		end
		connection:Disconnect()
	end
end

connection = blood.Touched:Connect(onTouched)

wait()

https://www.roblox.com/games/6185974488/Blood-Test?refPageId=dfe32dff-2db3-48d9-8d69-be5f14ac2e41

1 Like

Ok so working on a random set of situations needs some more information in order to understand what is happening when.
So perhaps try putting some prints of variables that effect the blood splatter and see if there is a pattern.
By the way I had to use Zoom in order to read your script.
Maybe using ``` before and after the code, which will format it , may make us more able to help.

Sorry it’s my first time posting on this lol, I updated it and posted a link to the game

Hello, so i used to have this problem but what i did is something a bit strange but understandable.

So what i did is i used the raycast hitbox and initialized it on a blood drip and added a attachment and then did a function on when it was hit and got a raycast result returned and finished by doing the same things you do when you get hit,pos,normal from the raycast result and it worked perfectly, Maybe you could try this. @Octik

Have you found your solution? Yet?

1 Like