Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can You Change the Radius of WorldToScreenPoint ?

Asked by 7 years ago

I'm currently trying to make a targeting system, but it's not working how I want it to. Whenever I try to make it work, it marks everything on my screen, yet I want it only to do that within a certain radius.(For example, looking through a scope; you can only see the things in front of you. That's what I meant by radius.) Is this even possible? Here is my script:


function Target() local b = Cam:WorldToScreenPoint(human.Torso.CFrame.p) if (b==true) then local Spot= Spot:Clone() Spot.Parent=human.Parent.Head end end
0
What do you mean by it marks everything on your screen? Cavedudemann 2 — 7y
0
It clones the spot to every humanoid on my screen. TROLLPLANET2 2 — 7y
0
It is posible, you need to create a view frustum representing the view of the scope and then do a frustum culling. It involves some math but you can start googling. If I have time I'll implement it, seems interesting doing it in Roblox. EDIT: Checked the API, WorldToScreenPoint does the math for you, it returns a secound value telling if that point is visible. Destrings 406 — 7y
0
Use a part's CFrame.lookVector to get the direction it's facing, then use one of many methods to get objects in this direction (raycasting?) then check if those objects are characters. Place the characters into a table for use when cloning Spot through a generic for loop. OniiCh_n 410 — 7y
0
Add on: match characters from table to WorldToScreenPoint characters to specifically those in front of you. OniiCh_n 410 — 7y

1 answer

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
7 years ago

So, WorldToScreenPoint actually returns a second value: a bool telling if the point is visible by the screen. I assume you want to put a Spot on every visible character in the camera.

function Target()
    local b, t = Cam:WorldToScreenPoint(human.Torso.CFrame.p)
    if t then
        local Spot = Spot:Clone()
        Spot.Parent = human.Parent.Head
    end
end
0
This really didn't fix my problem. Like I said before, I only want characters in front of me marked-not every character on the screen. TROLLPLANET2 2 — 7y
Ad

Answer this question