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

How do make it so that when you don't at a brick, it disappears? (FirstPerson)

Asked by 8 years ago

How to make a script that when a player looks at a brick, but looks away, the brick disappears? I've considered finding the lookvector of the character torso, but I don't know how to use it.

0
there's only a lookvector to a camera mightydifferent 85 — 8y
0
^ all cframes have lookvector. cabbler 1942 — 8y
0
any ideas? flufffybuns 89 — 8y

2 answers

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
8 years ago
Edited 8 years ago

This can be a good use of mouse.Target. Target will tell you if the mouse is touching the part. So you can simply wait until the part is the target, then wait until the part is not the target.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = workspace:WaitForChild('Part')

while true do
    part.Transparency=0.5
    repeat wait(1/3) until mouse.Target == part
    print('Looking at part')
part.Transparency=0
    repeat wait(1/3) until mouse.Target ~= part
    print('Stopped looking at part')
end
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

I'm interested to know a better way, but this is the simplest way I can think of.

WorldToScreenPoint

local player = game.Players.LocalPlayer
local cam = Workspace.CurrentCamera
local part = Workspace.Part

cam.Changed:connect(function()
    local pos, visible = cam:WorldToScreenPoint(part.Position)
    -- Tells you where the brick is on your screen and whether it's visible to the user
    -- If the brick is anywhere on your screen, then you're looking near or at it.
    part.Transparency = visible and 0 or 1
    -- if you aren't looking at it, then make it transparent, if you are, make it visible.
end)
0
what does the script do? flufffybuns 89 — 8y
0
Visible returns true or false if the brick is visible within your screen. If it returns false, then the brick isn't visible on your screen, ie you aren't looking at or near it. Azarth 3141 — 8y
0
where do i put the script? and is it a local script? (sorry if im being annoying, i just really want to know how to do this) flufffybuns 89 — 8y

Answer this question