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

Can you use the camera in touched functions?

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?

3 comments

0

This isn't a request site, but YES. IT IS POSSIBLE.

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?

1

Check this cool model out by Stickmasterluke! http://www.roblox.com/Blizzard-Outside-Gui-item?id=126903505

2 answers

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.

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

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