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

Is there some way to make object diseppear in the moment when player see it?

Asked by 5 years ago

Is there some way to make object diseppear in the moment when player see it?

0
U dont User#23365 30 — 5y
0
What do you mean by that exactly? What's the context? SteamG00B 1633 — 5y
0
Put the transparent settings on... User#25115 0 — 5y
0
Phleg you really like being off topic don't you? She's asking for a theory on how to detect when an object comes into the player's fov SteamG00B 1633 — 5y
View all comments (11 more)
0
If you made it transparent, it would always be transparent SteamG00B 1633 — 5y
0
*face palm* User#23365 30 — 5y
0
read the title again lol User#23365 30 — 5y
0
Ditto, it says in the moment a player sees it, I am actually interested in this question as well because it can have some cool horror game applications SteamG00B 1633 — 5y
0
You have to put a range script and make that a one room place so that once a player enters, a local function plays. CaptainD_veloper 290 — 5y
0
Couldn't you do this with raycasting on the edge of a player's fov? SteamG00B 1633 — 5y
0
ok thx Too_Short0 10 — 5y
0
Hold on a bit no one answered your question yet, don't thank anyone till it's answered :) SteamG00B 1633 — 5y
0
In the moment when a player sees it is the key phrase here, if it's transparent, then the player will never see it. It has to be visible first and then just as the player sees it, it turns transparent. SteamG00B 1633 — 5y
0
I try not to assume people are stupid if they come here, if they can find this site, then they can also google their question, and as we all know, google can provide answers faster than this. SteamG00B 1633 — 5y
0
You only come here if you can't find it on google SteamG00B 1633 — 5y

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

So I have an idea, haven't tested it yet, but you lock the player's camera so that the camera can only be turned with the players movement (forgot the name of the camera property). Then you raycast on the edge of the players fov so that when it detects an object it waits either .1 or faster and then turns the detected object transparent. If an object has already been detected and it is detected again, then it turns the object opaque again.

Mine is not the best answer, if you're talking about getting if a specific part is visible, but if you're talking about making every part in front of you invisible, then this is probably the best idea.

Ad
Log in to vote
0
Answered by
fredfishy 833 Moderation Voter
5 years ago
Edited 5 years ago

What you want is WorldToScreenPoint, which I wrote a little bit about here.

This can be used to return whether or not a part is visible on screen.

However, this doesn't take in to account parts that might be in the way - to solve this problem we can use GetPartsObscuringTarget.

Then finally, we want to run this locally on ever rendered frame, so we can use RenderStepped. Since this is running locally, it shouldn't place undue load on the server.

I wrote a little babby example - just put a brick in the workspace called "CanYouSeeMe", and put the code in a LocalScript in StarterPlayer.StarterPlayerScripts.

local seenPreviously = false
player = game:GetService("Players").LocalPlayer

function partSeen(p)
    local s = Instance.new("SelectionBox")
    s.Adornee = player.Character
    s.Parent = player.Character
end

conn = game:GetService("RunService").RenderStepped:Connect(function(t)
    if not seenPreviously then
        local target = workspace.CanYouSeeMe
        local camera = workspace.CurrentCamera
        local locationAndDepth, visible = camera:WorldToScreenPoint(target.Position)

        if visible then
            local obscuring = camera:GetPartsObscuringTarget({target.Position}, {target})
            if #obscuring > 0 then
                -- not visible
            else
                -- visible
                seenPreviously = true
                partSeen(workspace.CanYouSeeMe)
                conn:Disconnect()
            end
        end
    end
end)

Using both conn:Disconnect() and seenPreviously is doing the same thing twice, but one might be easier to use than the other depending on what you're doing.

0
So then you would use this modified a bit so that when the part is visible, it makes it transparent? SteamG00B 1633 — 5y
0
Yeah I guess, or do whatever you wanted to do in your horror game thingy. It'd be a little hard for an example script to show you a brick turning transparent the first time you saw it, since you'd never see it solid,. fredfishy 833 — 5y

Answer this question