How to tell if a part touched a player's back

I would like to tell which face a part touches of a character’s torso and, if that face is the back.
I don’t know how to word this better sorry.

I found this script which I thought might help but I don’t really understand it:

function getSurface(position, object)
	local surfaces = {
		back = object.CFrame * CFrame.new(0, 0, object.Size.Z);
		front = object.CFrame * CFrame.new(0, 0, -object.Size.Z);
		top = object.CFrame * CFrame.new(0, object.Size.Y, 0);
		bottom = object.CFrame * CFrame.new(0, -object.Size.Y, 0);
		right = object.CFrame * CFrame.new(object.Size.X, 0, 0);
		left = object.CFrame * CFrame.new(-object.Size.X, 0, 0);
	}
	local surface = "back"
	for side, cframe in pairs (surfaces) do
		surface = ((position - cframe.p).magnitude > (position - surfaces[surface].p).magnitude and surface or side)
	end
	return surface
end


thanks

You cannot determine exactly where the touch happens, you’ll have to make a small hitbox on the player’s back instead.

1 Like

like welding a part to a player’s back when they join or something?

Yes, it would be welded to the player’s HumanoidRootPart. An uncollidable, massless, and unanchored part. Also, set the CustomPhysicalProperties to set the Density to 0.

1 Like

You can use this function to get the angle between a CFrame and a Position

local function getAngleBetween(origin: CFrame, target: Vector3): number
	local lookVector: Vector3 = origin.LookVector
	local unit: Vector3 = (target - origin.Position).Unit

	return math.deg(math.acos(unit:Dot(lookVector)))
end

To determine if a Part is behind a player,

local angle = getAngleBetween(character:GetPivot(), part.Position)

if angle >= 135 then
    print("Part is behind the Player's Character")
end
1 Like

so there is a slight problem, you can hit the part through the player’s torso:

I’m not sure if I should make this another topic or not

also thanks for your help!

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