Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

15 comments

0

U dont

0

What do you mean by that exactly? What's the context?

0

Put the transparent settings on...

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

0

If you made it transparent, it would always be transparent

0

face palm

0

read the title again lol

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

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.

0

Couldn't you do this with raycasting on the edge of a player's fov?

0

ok thx

0

Hold on a bit no one answered your question yet, don't thank anyone till it's answered :)

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.

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.

0

You only come here if you can't find it on google

2 answers

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.

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.

2 comments

0

So then you would use this modified a bit so that when the part is visible, it makes it transparent?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.