How would I detect which side of the door a player is on?

Currently making a door, trying to make it as accurate as possible to how a door would work irl. I tried using dot product, however, it’s very inaccurate, back side returns a negative number, same with front side.

Code:

local model = script.Parent.Parent.Parent;

local prompt = script.Parent;

local front = model:WaitForChild("front");
local back = model:WaitForChild("back");

local opened = false;

prompt.Triggered:Connect(function(player)
	local direction = (player.Character:WaitForChild("HumanoidRootPart").Position - model.Parent:WaitForChild("Handle").Position);
	if direction:Dot(model.Parent:WaitForChild("Handle").CFrame.LookVector) > 0 then
		print('true');
	else
		print('false')
	end;
end);
1 Like

if you mean Touching and two different parts (like back, front, left, right all different)
then you could try using side.Touched:Connect()

2 Likes

I solved it by using magnitude, front and back side, then checking. If that didn’t work then I would’ve tried this. Thanks!

1 Like

You can use the Dot Product if your solution isn’t so effective.

1 Like

I tried that, look above ^^^ It wasn’t working so I just tried magnitude instead.

2 Likes