EDIT: I am not the best with math, however I assume you could combine this absolute value equation with an angle measurement to find a 2D conical shape. If you want to move it to 3D, make sure to multiply by pi.
The steps you’d have to take would be to get the angle of the parts relative to the orientation of the object with the cone, then check if they are within ±half of the angle you want (120/2 = 60)
local function CheckAngle(Player,Object)
local Distance = (Object.Position - Player.Character.Head.Position);
local LookVector = (Player.Character.Head.CFrame.lookVector);
return math.deg(math.acos(Distance:Dot(LookVector) / (Distance.magnitude * LookVector.magnitude)));
end
This is one from my “util” library I use too get the angle between the players face and anthor object, allowing me to check if they are facing said object. You can apply @inlikewithyou logic to actually limit the range of the cone.
That’s a pretty good solution. Can adjust a couple of small things if you want.
The “Distance” name here is a misnomer since that is actually a Vector3 (so don’t let that confuse you). For the same result, you can change:
local Distance = (Object.Position - Player.Character.Head.Position).Unit
...
math.deg(math.acos( Distance2:Dot(LookVector) ))
Remove all the player references and just use object1 and object2 as args to make the fn more general.
Also, if you don’t need the exact angle value (the value you get with math.deg(math.acos(…))) then you can get away with just using the Distance:Dot(LV) bit and checking the values you get with that. If the lookVector of your object (blue sphere) is looking directly at the other object then the value will be 1. If it is at a 90 deg angle the value will be 0. If the object is behind it will be a negative value. So you can set a condition that says the value returned by Dot needs to be positive and greater than, say, 0.7, and it will eval to true if the blue object is looking more or less at the other. I usually just eyeball that number value to something that looks right, but It’s probably a sine or cosine value that ranges from 0 to 1. If that’s correct, then a 60 deg from center cone (your 120 above) would probably be 0.5 (instead of 0.7).
Anyway, VineyardVine’s suggestion is on track. Let me know if I can be more clear with some of this, I got a bit stream-of-consciousness-y there.