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

How to check if a player is facing a certain object?

I'm attempting to activate a function when a player's head is facing a certain object.

I've tried using

(Humanoid.MoveDirection:Dot(workspace.CurrentCamera.CFrame.RightVector) <= 0.25)

but it turns out that it activates when a player isn't moving much to the right.

2 answers

you can make the game first person and then if player's mouse is touching them execute the event or do something

you can do it like that

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

if mouse.Target == "The Object" then
print("put anything here")
end

1 comment

0

It's not going to be in first person though.

local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if withinScreenBounds then
   -- We have successfully detected if the player can see the part.
end

not sure I understood your question correctly but this should help you.

3 comments

0

I'm not looking for when a certain object appears in a player's FoV. I'm looking for an answer that helps me make a function for when a player's head is facing a specific object.

0

You can see if 2 players are facing each other by doing math.deg(math.acos(lookVector1.unit:Dot(lookVector2.unit)))

0

So how does that work, make it into an answer

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