local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
repeat task.wait() until player.Character or player.CharacterAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local HRP = character:WaitForChild("HumanoidRootPart")
local Head = character:WaitForChild("Head")
local Looking_NPC = workspace:WaitForChild("Looking_NPC")
local NPC_HRP = Looking_NPC:WaitForChild("HumanoidRootPart")
local NPC_Head = Looking_NPC:WaitForChild("Head")
local Bounding_Part = workspace:WaitForChild("Bounding_Part")
local OverlapParameters = OverlapParams.new()
OverlapParameters.FilterType = Enum.RaycastFilterType.Exclude
OverlapParameters.FilterDescendantsInstances = {Bounding_Part, Looking_NPC, workspace.Lobbies.Secondary_Lobby.Baseplate}
local function Check_Player(Parts_List)
local Found_Player = false
for i, Part in Parts_List do
if Part.Name == "Handle" and (Part.Parent:IsA("Accessory") or Part.Parent:IsA("Tool")) and Players:GetPlayerFromCharacter(Part.Parent.Parent) or Players:GetPlayerFromCharacter(Part.Parent) then
Found_Player = true
end
end
return Found_Player
end
while true do
local Parts_In_Bound = workspace:GetPartBoundsInBox(Bounding_Part.CFrame, Bounding_Part.Size, OverlapParameters)
print(Parts_In_Bound)
local Found_Player = Check_Player(Parts_In_Bound)
local Dot_Product = NPC_HRP.CFrame.LookVector:Dot(HRP.CFrame.LookVector)
print(Dot_Product)
if Found_Player == true then
if Dot_Product >= 0.5 then
print("Player is within the NPC's FOV!")
local LookAt_CFrame = CFrame.lookAt(NPC_Head.Position, Head.Position)
local X, Y, Z = LookAt_CFrame:ToOrientation()
TweenService:Create(NPC_Head, TweenInfo.new(0.2, Enum.EasingStyle.Linear), {Orientation = Vector3.new(math.deg(X), math.deg(Y), math.deg(Z))}):Play()
else
print("Player is not within the NPC's FOV!")
end
else
print("Didn't find player!")
end
task.wait(1)
end
Hello! I’m trying to practice :GetPartBoundsInBox() and Dot Products and I was trying to practice them by attempting to create an NPC that looks at a player whenever the player is in the box and within the NPC’s FOV range. However, I don’t understand why this isn’t working and I think it should? Can anyone help me with this and Dot Products?
