Help with object view

  1. 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.

  2. What is the issue? Include screenshots / videos if possible!
    I can’t figure a way to detect if they are within the window.

  3. 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
Screenshot 2025-03-19 095439
All these humanoids are within the window and need to be highlighted.

3 Likes

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

1 Like

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.

1 Like

Can you give me a example of how to execute this?

1 Like

How would the mouse work? The target would be the glass firstly, and secondly it would only do 1 target

1 Like

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.

2 Likes

Just realized, if you are reloading wouldn’t it still detect?

1 Like

Then you can disable it while reloading, no?

1 Like

Theres sway. And a feature which can like i don’t know how to explain it but it wont work with this method

Let me get this clear, you want to highlight all humanoids that are within the area of the lens correct?

So, how would sway and the “feature that you don’t know how to explain” bug this out? This system would be independent of all other systems you have.

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.

you can probably use blockcast and just position itself where that screen is and as well resize it.

The issue with block cast is that it won’t allow for the FOV. FOV is an angle, measured in degrees while block cast is just an elongated cuboid.

Something like:

(The box represents the block cast ray and the dots represents the humanoids.)

ah i see now, makes sense. thanks for letting me know this beautiful information.

No worries!

Just a side note that I apologize for the poorly drawn illustration. I am not really good on my drawing side.

Is the window a GUI object or an actual part? I was thinking it was a GUI object for the mouse option but if it’s a part, then that wouldn’t work.

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

Exactly, I was using boxcast and it wouldn’t work properly.

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.