How can i find a relative point on a part?

I’m trying to work on a gore system, and I think a good course of action would be to find where the player hit on a part, so I’m working on a script for testing it out before I implement it into a module, however I’m running into trouble

The system works for finding where a player hits the NPC, however I’m having some trouble trying to make it work when the part is rotated

heres what i have right now:

local PartToCheck = game:GetService("Workspace"):WaitForChild("check")
local Pos = game:GetService("Workspace"):WaitForChild("Pos").Position

game:GetService("RunService").Heartbeat:Connect(function()
	Pos = game:GetService("Workspace"):WaitForChild("Pos").Position
	PartToCheck = game:GetService("Workspace"):WaitForChild("check")
	local PosCF = CFrame.new(Pos)
	local relativeCFrame = PosCF:ToObjectSpace(PartToCheck.CFrame)
	
	local Left = false
	local Top = false
	local Front = false
	local Middle = false
	
	if relativeCFrame.Y > 0.25 then
		Top = false
	elseif relativeCFrame.Y < -0.25 then
		Top = true
	else
		Middle = true
	end
	
	if relativeCFrame.Z > 0 then
		Front = true
	else
		Front = false
	end
	
	if relativeCFrame.X > 0.25 then
		Left = true
	elseif relativeCFrame.X < -0.25 then
		Left = false
	else
		Middle = true
	end
	
	if Middle == true then
		if Front then
			print("Front Center")
		else
			print("Back")
		end
	else
		if Left and Top then
			print("Top Left")
		elseif Left and not Top then
			print("Bottom Left")
		elseif not Left and Top then
			print("Top Right")
		elseif not Left and not Top then
			print("Bottom Right")
		else
			print("Somehow in the middle")
		end
	end
end)

As I said it works perfectly fine without rotation on the part I’m checking, but once i rotate it, it breaks entirely

I recommend that you use attachments, they’re a live savior for me

can’t believe i overlooked that :skull:

1 Like

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