I wanted to make a block that if player looks on it its just explodes…
then i searched something in toolbox, and it was nothing
that’s it
i need help
You’ll be wanting WorldToVorwportPoint.
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint
You can use WorldToVorwportPoint to check if the object is in front of the camera, then use raycasting to determine if the view is blocked.
Use clickdetector with the event MouseHoverEnter, with the and also set the icon to the default icon
nah
i tried it wont work + this is stupid because i just dont want to mouse it
Hmm can you please elaborate? Because Im not sure if you want a mouse over the block and then it explode, Or the block in your screen then it explode
50/50
screen and mouse if to be exact
I would do an angle check between the player’s current camera/head orientation vector and the vector pointing from the camera/head to the part:
In a LocalScript:
llocal specialPart = workspace.Part --// idk what your part is
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character.Head
local CAMERA_ANGLE_THRESHOLD = 30 --// camera angle threshold in degrees
local HEAD_ANGLE_THRESHOLD = 30 --// head angle threshold in degrees
function stepped(dt)
local clv = camera.CFrame.LookVector
local hlv = head.CFrame.LookVector
local ctp = (specialPart.Position - camera.CFrame.Position).Unit
local htp = (specialPart.Position - head.Position).Unit
local cameraAngle = math.deg(math.acos(clv:dot(ctp)))
local headAngle = math.deg(math.acos(hlv:dot(htp)))
if cameraAngle > CAMERA_ANGLE_THRESHOLD then
--// add functionality here
end
if headAngle > HEAD_ANGLE_THRESHOLD then
--// add functionality here
end
end
game.RunService.RenderStepped:Connect(stepped)
This makes it so that if the camera/head is facing a region within 30 degrees of the part, something will happen. You can add an extra distance check to make sure that the player can’t “see” the part from so far, and a raycast to make sure that the player can actually see the object and it’s not being blocked by a bigger object in front of it. Otherwise, @JarodOfOrbiter’s answer also works.
Ty but it had some bugs that i fixed and there the full working script
local specialPart = workspace.Part --// idk what your part is
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character.Head
local CAMERA_ANGLE_THRESHOLD = 30 --// camera angle threshold in degrees
local HEAD_ANGLE_THRESHOLD = 30 --// head angle threshold in degrees
function stepped(dt)
local clv = camera.CFrame.LookVector
local hlv = head.CFrame.LookVector
local ctp = (specialPart.Position - camera.CFrame.Position).Unit
local htp = (specialPart.Position - head.Position).Unit
local cameraAngle = math.deg(math.acos(clv:Dot(ctp)))
local headAngle = math.deg(math.acos(hlv:Dot(htp)))
if cameraAngle > CAMERA_ANGLE_THRESHOLD then --//Camera doesnt look
print("Camera Angle")
end
if headAngle > HEAD_ANGLE_THRESHOLD then --//Head doesnt look
print("Head Angle")
end
end
game:GetService("RunService").RenderStepped:Connect(stepped)
but ty
The two scripts are the same.
llocal specialPart = workspace.Part --// idk what your part is
You just fixed the minor spelling issue here, you should really mark their post as the solution (as it is what brought you to a solution).
nope first llocal then :dot => :Dot theres alot of small things that u didnt notice
- if future ppl will come (ofc they wont but i always doing that) they will copy the wrong one
You mention ‘a lot’ but the only other issue was the capitalisation of ‘d’ in ‘dot’.
are u sure? huh???
heheeh
lol