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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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
0
It's not going to be in first person though. MaikeruJonson_JP3 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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.

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. MaikeruJonson_JP3 4 — 4y
0
You can see if 2 players are facing each other by doing math.deg(math.acos(lookVector1.unit:Dot(lookVector2.unit))) kaspar1230 345 — 4y
0
So how does that work, make it into an answer MaikeruJonson_JP3 4 — 4y

Answer this question