![]() Table.remove(playersseen, table. If not table.find(playersseen, player) then Local dotproduct = npctoplayer:Dot(npclv) Local npctoplayer = (character:WaitForChild("Head").Position - head.Position).Unit Ik my explaination is not very good, so if anyone has a better explaination feel free to reply to my postįor _, player in pairs(game.Players:GetPlayers()) do Next, we subtract by 1 because we need to get 35 degrees from the "straight ahead" We should now get the converted value of 35 degrees (if npcfov is 70) Then you multiply it by half of the fov (half for each side) Hence in order to get the 70 degrees of fov, you first need to find the conversion for the degrees As it approaches 0 and 180 degrees, the dot product goes toward 0 When the player is right in front of the npc (90 degrees), the dot product returns 1 THE "NPCFOV" IS JUST THE AMOUNT OF "DEGREES" THE NPC CAN SEE NOTE THAT THE "NPCFOV" MAY NOT BE TRUE FOV, BECAUSE I HAVE NO IDEA HOW IT WORKS LOL Note that this code does not care about range.): local rs = game:GetService("RunService") ![]() You can undo the comments on the prints if you want a visual output, but you can also use the “playersseen” table to detect which players are in the npc’s fov. ![]() :Dot() goes from -1 to 1, so if you want to have say 70 degrees of fov, you would have this (Code goes inside npc. Edit: If a player leaves, any other code you add to this script may break (Kind of obvious but just want to clarify for any new scripters who may stumble across this 's works but you I you might have to change the value depending on how much you want your npc to see. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |