How do I get a block face/side, from a rotated part, while still being accurate

I have a system where the mouse does a raycast to blocks, I need to make it to where you run a certain command it gets a NormalId, I have a system for this already, it just doesnt work with rotation, rotation offsets the NormalId

pretend this is a rotated part, and you need to place a particle emitter on it or something, and you are getting the side of it, and since its rotated, it will be on a completely different side.
image

I have pretty much tried as much as I could.

This is what I have so far.

function f.mouseBlockSide()
	local target, pos = f.raycastMouse()
	local offset = pos-target.Position
	local lNum = 0
	local largestAxis
	for _, axis in pairs({'x', 'y', 'z'}) do
		local value = offset[axis]
		if math.abs(value) >= lNum then
			lNum = math.abs(value)
			largestAxis = axis
		end
	end
	if largestAxis == 'x' then
		return Vector3.new(offset.X, 0, 0).Unit
	elseif largestAxis == 'y' then
		return Vector3.new(0, offset.Y, 0).Unit
	elseif largestAxis == 'z' then
		return Vector3.new(0, 0, offset.Z).Unit
	end
end

Is this something ur looking for? Look at the solution.
How would I get the face of a part that the mouse is pointing at? - Help and Feedback / Scripting Support - DevForum | Roblox

1 Like

I’ll check this out. Thanks, testing it now.

Okay, it does not work, well… yes technically, but its what I had before, but more code. im trying to make it to where it locks onto the rotation as well.
Should that work there with rotated parts?

Edit: it seems to work, but sometimes uses the wrong face sometimes, but works better than before.
Thanks!

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