Can't align part to normal of part (Raycast)

Hello, I’m trying to make a blood system that makes some blood parts align with the normal of the part that gets hit by raycast.

I use this formula

NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position + results.Normal)

But the end result end up looking like this:

I have tried rotating the CFrame after with 90 degress on all axes.

How do you make them align???

That’s how you’d do it. What did the script look like when you were doing that?

NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position + results.Normal) * CFrame.new(math.rad(90),0,0)

lookAt will always have two directions it doesn’t work right in:

The alignment looks fine now, there’s just one problem, they’re inversed, which means they are on the inside of the part instead of outside

It looks like this now, they’re not invisible but they are on the wrong side of the face.
image
How can i fix that?

Reverse the direction of the “up” parameter, the third parameter to lookAt

This is the code that sets the lookAt now:

if math.abs(results.Normal.Z) ~= 1 then
	NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position - Vector3.zAxis, results.Normal);
else
	NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position - Vector3.xAxis, results.Normal);
end

How would i inverse the vector3 and where do i put it. I’m so lost when it comes to CFrame

Reverse the two result.Normals like this:

if math.abs(results.Normal.Z) ~= 1 then
	NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position - Vector3.zAxis, -results.Normal);
else
	NewSplat.CFrame = CFrame.lookAt(results.Position, results.Position - Vector3.xAxis, -results.Normal);
end

That works thank you!

Do you have any suggestions on where to learn about these type of things. New Roblox documentation sucks.

1 Like

I have a vector math intro paper that isn’t finished yet but I can send it to you if you want to read it early.

That would be great! My discord is: Clickzy#0001

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.