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

If looking at brick statment?

I am currently trying to make an event that occurs when a player looks at a brick, I've tried a lot of things, but none was successful, anyone?

1 comment

0

Do you want to detect if the part is visible on the camera? Or if the player's character is generally looking at the part? For the first you can use WorldToScreenPoint(), and for the latter you could probably use dot product.

1 answer

✓ Accepted answer

One "hacky" of doing this is using the Camera:WorldToScreenPoint method.


local m = game.Players.LocalPlayer:GetMouse()

m.Button1Down:Connect(function() 
	local camera = workspace.CurrentCamera
	local worldPoint = workspace.Baseplate.Position
	local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
	
	print(onScreen) -- true if it's on the screen
	print(vector)
end)

A problem with this can be found by AllYourBlox's post here

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