How would i get the CFframe on the new raycast roblox?

So i have been searching long and far to find out how to get a cframe of a ray

local CastRayCast = function()
			local RayDirection = Vector3.new(0, -1.5, 0)
			local RayCastParameters = RaycastParams.new();
			
			local RayOrgin = Leg.Position
			
			RayCastParameters.FilterDescendantsInstances = {Character};
			RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
			local BloodCastRay = workspace:Raycast(Leg.Position, RayDirection, RayCastParameters)
			return BloodCastRay
		end

A Ray doesn’t have a CFrame, it’s just an origin and a direction.

Could you clarify what you mean? Do you want the CFrame of the part that you hit? Or maybe the normal vector of the surface you hit?

1 Like

Im not really sure as im new to raycasting but i think the raycastingresult How to get CFrame from RaycastResult

Maybe it would help if you explained why you need whatever it is you’re asking for?

Im making a blood system so i want the blood splat to face the ray

The RaycastResult returns a dictionary with these indexes + values:

Instance - the instance/terrain cell that got hit by it
Position - the vector3 position it hit the instance/terrain cell
Material - the material of the instance/terrain cell that got hit by it
Normal - the normal of the face of the thing that got hit by the ray

So atleast for what you are asking for the position and the normal are the important things for you, the normal is pretty much where the specific face is looking at (so basically it would be one of the components of cframe), so you can make the blood face the normal vector.


I tried this, but it sortaaa works problem is the blood kinda tilts

local BloodSystem = function(Player)
	if Player ~= nil then
		local TweenService = game:GetService("TweenService")
		
		local Character = Player.Character or Player.CharacterAdded:Wait();
		local Humanoid = Character:WaitForChild("Humanoid");
		local Leg = Character:WaitForChild("Left Leg");
		
		local CurrentHumanoidHealth = Humanoid.Health;
		
		local BloodParticle = script:WaitForChild("Blood_Particle");
		
		local CastRayCast = function()
			local RayDirection = Vector3.new(0, -1.5, 0)
			local RayCastParameters = RaycastParams.new();
			
			local RayOrgin = Leg.Position
			
			RayCastParameters.FilterDescendantsInstances = {};
			RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
			local BloodCastRay = workspace:Raycast(Leg.Position, RayDirection, RayCastParameters)
			return BloodCastRay
		end
		
		local CreateBlood = function()
			local BloodPosition = CastRayCast()
			if BloodPosition then
				local BloodPart = Instance.new("Part", workspace.Assets.BloodParticle)
				BloodPart.Name = "Blood_Particle"
				BloodPart.CanCollide = false
				BloodPart.Anchored = true
				BloodPart.Position = BloodPosition.Position
				BloodPart.Orientation = Vector3.new(90,0,0)
				BloodPart.Size = Vector3.new(4, 4, 0.001)
				BloodPart.Transparency = 1
				
				local BloodDecal = Instance.new("Decal", BloodPart)
				BloodDecal.Name = "Blood"
				BloodDecal.Texture = "rbxassetid://890286383"
			end
		end
		Humanoid.HealthChanged:Connect(function(newHealth)
			if newHealth < CurrentHumanoidHealth then
				CurrentHumanoidHealth = newHealth
				print("blood created")
				CreateBlood()
			end
		end)
	end
end
return BloodSystem

You could use CFrame.fromAxisAngle with the raycast Normal as the axis.

Change the Orientation and Position things to this:

BloodPart.CFrame = CFrame.lookAt(BloodPosition.Position, BloodPosition.Normal)

image

				local BloodPart = Instance.new("Part", workspace.Assets.BloodParticle)
				BloodPart.Name = "Blood_Particle"
				BloodPart.CanCollide = false
				BloodPart.Anchored = true
				BloodPart.Size = Vector3.new(4, 4, 0.001)
				BloodPart.Transparency = 1
				BloodPart.CFrame = CFrame.lookAt(BloodPosition.Position, BloodPosition.Normal)