What do you want to achieve? Keep it simple and clear!
I want to make it so that humanoids that are within the sight window are given a highlight.
What is the issue? Include screenshots / videos if possible!
I can’t figure a way to detect if they are within the window.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I searched on the developer hub, but nothing really showed any solutions. The current method I’m using is a raycast but it has to be from the window not from a raycast as you will have to look at it directly.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
How would I detect it? Heres some images of what I mean
All these humanoids are within the window and need to be highlighted.
You could get the player’s mouse and then check if the target is a humanoid.
For example:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse
if mouse.Target:IsA("Humanoid") then -- Or use a different if statement
-- Highlight humanoid
end
You can use dot product to see if the humanoids are within a certain angle. Or you can project their three dimensional position to two dimensions and check if they are within the two dimensional position of the sight.
Something like: ourCamera.LooKVector:Dot(ourCamera.CFrame.Position - humanoid.RootPart.Position) which would return the cosine of the angle that the humanoids subtends with respect to the players sight. What you can do is use math.acos() to convert the returned value into radians and using “<” to check if the given angle in radians is within certain bounds.
Yes, I want the lens to highlight all humanoids in its area. The sway is very sensitive so it might bring the optic out of view. And your method isn’t relative to the lens itself
Oh now I understand your concern. Well my method isn’t effective because it’s a concept. I understand your frustration now.
A fix for this is to use the lens’s look vector rather than the cameras look vector. This would be relative to the lens and would accurately fill out all possible humanoids.
The window UI is a part. That’s when the mouse wouldn’t work, even if it wasn’t, it would only have 1 target then the other 2 rigs wouldn’t be affected
Yep and now you know why. The only best method I see is using dot product and such.
Just like I said, you need to do: Lens.CFrame.LookVector:Dot(Lens.Position - Humanoid.RootPart.Position) which returns a cosine of the angle subtended by the humanoids RELATIVE to the LENS this time.