Please read update at the bottom of the page first
Hi. I am currently working on a blood splatter system and it partially works. The intention of the system is to create blood splatters which stick to walls, however they dont orient properly on walls and some splatters are underground.
Script:
BloodModule.NewParticle = function(originPos)
local particle = game.ReplicatedStorage.BloodParticle:Clone()
local c
particle.Parent = workspace
particle.Position = originPos
particle.Velocity = Vector3.new(math.random(minParticle,maxParticle),math.random(minParticle,maxParticle) + 30,math.random(minParticle,maxParticle))
c = particle.Touched:Connect(function(hit)
if hit.Anchored then
particle.Anchored = true
warn("Touched: ".. hit.Name)
c:Disconnect()
local rayParams = RaycastParams.new()
rayParams.IgnoreWater = true
rayParams.FilterDescendantsInstances = {hit}
rayParams.FilterType = Enum.RaycastFilterType.Whitelist
local raycastResult = workspace:Raycast(particle.Position + particle.Size --[[ Adding particle size because otherwise the raycasting barely works? ]], hit.Position, rayParams) -- using raycasting to get surface normals which *should* allow the splatters to correctly orientate
if raycastResult then
local splatter = Instance.new("Part")
splatter.Parent = workspace
splatter.Size = Vector3.new(5,0.5,5)
splatter.Anchored = true
splatter.Color = Color3.fromRGB(76, 0, 1)
splatter.CFrame = CFrame.new(particle.Position, particle.Position + raycastResult.Normal)
splatter.Rotation = splatter.Rotation + Vector3.new(0,90,0) -- adding rotation because without it, the blood splatters are disoriented even on the ground, might need to change however
end
end
end)
return particle
end
Showcase:
Showcase without the
splatter.Rotation + Vector3.new(0,90,0)
lineUPDATE
I fixed the worked around the rotation problem by rescaling the blood part to 5, 5, 0.5 but this method doesnt work when using cylinder part types because it becomes disoriented.
BloodModule.NewParticle = function(originPos)
local particle = game.ReplicatedStorage.BloodParticle:Clone()
local c
particle.Parent = workspace
particle.Position = originPos
particle.Velocity = Vector3.new(math.random(minParticle,maxParticle),math.random(minParticle,maxParticle) + 30,math.random(minParticle,maxParticle))
c = particle.Touched:Connect(function(hit)
if hit.Anchored and hit.Name ~= "BloodSplatter" and hit.Name ~= "BloodParticle" then
particle.Anchored = true
warn("Touched: ".. hit.Name)
c:Disconnect()
local rayParams = RaycastParams.new()
rayParams.IgnoreWater = true
rayParams.FilterDescendantsInstances = {hit}
rayParams.FilterType = Enum.RaycastFilterType.Whitelist
local raycastResult = workspace:Raycast(particle.Position + particle.Size --[[ Adding particle size because otherwise the raycasting barely works? ]], hit.Position, rayParams) -- using raycasting to get surface normals which *should* allow the splatters to correctly orientate
if raycastResult then
local splatter = Instance.new("Part")
splatter.Parent = workspace
splatter.Size = Vector3.new(0,0,0)
local factor = math.random(2,6)
TS:Create(splatter, TweenInfo.new(1), { Size = Vector3.new(factor, factor,0.5) }):Play()
splatter.Shape = Enum.PartType.Cylinder
splatter.Anchored = true
splatter.Color = Color3.fromRGB(76, 0, 1)
splatter.CanCollide = false
splatter.CanTouch = false
splatter.CFrame = CFrame.new(particle.Position, particle.Position + raycastResult.Normal)
end
end
end)
return particle
end