How to use normals for blood script?

I am creating a blood script, and I need to use normals to get the blood to the right orientation of the raycast. But for some reason I can’t get it to get the right angle.

I’ve tried using free models to look for any examples, asked others, but didn’t help really. Just got an understanding of what it is.

Script:

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder", game.Workspace)
	Folder.Name = "BloodFolder"
	plr.CharacterAdded:Connect(function(char)
		print(char.Name)
		
		local hum = char:FindFirstChildOfClass("Humanoid")
		local oldHealth = hum.Health
		
		hum.HealthChanged:Connect(function()
			
			
			local humanoidRoot = char:WaitForChild("HumanoidRootPart")
			local rayDirection = Vector3.new(math.random(-120, 120),math.random(-120, 120),math.random(-120, 120))
			
			local raycastparams = RaycastParams.new()
			raycastparams.FilterDescendantsInstances = {char, Folder:GetChildren()}
			raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
			local raycastResult = workspace:Raycast(humanoidRoot.Position, rayDirection, raycastparams)
			
			--blood sizes
			local size1 = Vector3.new(3, 0.34, 3)
			local size2 = Vector3.new(5, 0.34, 5)
			local size3 = Vector3.new(6.5, 0.34, 6.5)
			
			local random = math.random(1,3)
			
			if raycastResult then

				local blood = game.ServerStorage.BloodPart:Clone()
				local hitPart = raycastResult.Instance
				
				blood.CFrame = CFrame.new(raycastResult.Position)
				blood.CFrame = CFrame.lookAt(raycastResult.Normal,raycastResult.Normal,raycastResult.Normal)
				blood.Parent = Folder
				
				local tweenservice = game:GetService("TweenService")
				-- create size with tweenservice
				if random == 1 then
					local info = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal = {Size = size1}
					local expand = tweenservice:Create(blood,info,goal)
					expand:Play()
				end
				if random == 2 then
					local info2 = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal2 = {Size = size2}
					local expand2 = tweenservice:Create(blood,info2,goal2)
					expand2:Play()
				end
				if random == 3 then
					local info3 = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal3 = {Size = size3}
					local expand3 = tweenservice:Create(blood,info3,goal3)
					expand3:Play()
				end
			end
		end)
	end)
end)

Yes, its kinda junky but it works. I just need the raycast normal for now :^)

Anything helps!

1 Like

I think this might be what you’re looking for… I’ve not tested it but I think it should work.

blood.CFrame = CFrame.new(raycastResult.Position, raycastResult.Position + raycastResult.Normal) * CFrame.new(0,0,-blood.Size.Y / 2)
1 Like

Capture
It didn’t quite work out the way I wanted it to…

I think it’s because the top of that part isn’t what would actually be considered the top. You’ll have to calculate the rotation based off which surface you want pointing upwards. I think you’ll find what you need here:

Alr, I will try it out and let you know what happens, just fixing a few things

The post looks VERY confusing. And also it didn’t really help rotating the part :^(