How could I cut directions around the player into sections?

I want to achieve three variables that represent sections around my player the game is gonna be in 2d. The three directions are ‘left’, ‘right’, and ‘up’. To accomplish something like this;


I want these to tell if the image label enters them if it does then do something. But still note the game is technically still 3d so I would have

I would use just a couple dot product tricks

pos is the position of the thing youre checking which sector its in
hrp is the humanoidrootparts cframe

Check #1
Right/left check:

rl = hrp.RightVector:Dot(pos-hrp.p) --greater than 0, right side, less than 0, left side

Check #2
Angle check:

ang = math.acos(hrp.LookVector:Dot((pos-hrp.p).Unit)) --angle from front

Here are some example cases
I will be assuming you want a 60 degree front sector “angle”

rl > 0 and ang > 30 --right sector
rl < 0 and ang > 30 --left sector
ang <= 30 --middle sector

(Side note, make sure (pos-hrp.p) has a y value of 0, assuming you mean a flat on the ground sector)

This is the solution I literally just thought of but I’m glad you responded because I don’t know how I would implement this.

1 Like

Hey hate to rehash this but I don’t think this will work I tried code like

local mouseVector = (Vector3.new(mouse.X, mouse.Y, 0)).Unit;
print(humanoidRootPart.CFrame.LookVector:Dot((mouseVector-humanoidRootPart.CFrame.p).Unit))

The problem is it changes when I move why does it do that? it gives me like a 0.4 to 0.6 range at first then it changes to like -0.99999 after moving and I don’t know why this is called in runservice btw here’s a video.

sorry for the poor example like me glitching through the wall but you get the gist.

I solved the problem with ViewportToWorldPoint then divided it in half then checked the mouse position with it.