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

Can you use the camera in touched functions?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Is it possible to detect if your camera is 'in' a brick? For example, I have this script that when your head touched and stops touching this 'water' brick, the script makes a 'water blur' Gui visible/invisible. Is it possible to have it run the script when the brick is 'inside' of it instead of the head?

0
This isn't a request site, but YES. IT IS POSSIBLE. deputychicken 226 — 8y
0
Is there a certain event for it? I looked on the wiki but touched doesn't really seem like it's used for it. Is touched only used for parts? ghostblocks 74 — 8y
1
Check this cool model out by Stickmasterluke! http://www.roblox.com/Blizzard-Outside-Gui-item?id=126903505 Redbullusa 1580 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

In a localscript you could frequently check workspace.CurrentCamera.CoordinateFrame, which gives you the CFrame of the current camera. You can check its position with .p. If the brick you're working with is rotated, this function may be useful:

function PointInPart(point, part)
    point = part.CFrame:pointToObjectSpace(point)
    return math.abs(point.X) <= part.Size.X / 2
        and math.abs(point.Y) <= part.Size.Y / 2
        and math.abs(point.Z) <= part.Size.Z / 2
end

Use it like this:

cameraInPart = PointInPart(workspace.CurrentCamera.CoordinateFrame.p, partHere))

You could listen to changes to the Camera (using a Changed event), or just use a while loop to check the condition at regular intervals.

Ad
Log in to vote
-1
Answered by 8 years ago

Your question was 'is this possible', my answer is yes, this is 100% possible.

Answer this question