Alright so, I’ve been working on an AI for the past couple days. Where it moves when you don’t look at it, and also when the player “Blinks” (It’s an SCP-173)
I have it working well, but right now it just works on a timer. Haven’t implemented the blink mechanics yet. So right now I’m figuring out a solution to him being able to move when a player looks away/turns their back to him.
My current idea is to cast a ray in front of every player’s head, and check if the ray is touching the HumanoidRootPart of 173. If so, then it will wait on the blink time to hit 0, then he will advance towards the player.
All the necessary things such as killing the player and moving towards the player is done. I just need to have the control for his movement.
This is multiplayer, so my idea is that for each ray that’s touching him. It will add to the blink timer, to slow 173 down.
1 - How should I cast the ray?
2 - How do I count the amount of rays that are touching the HumanoidRootPart? (In other words; how do I count the amount of players looking at the HumanoidRootPart?)
Any help would be appreciated, if you need any further explanation let me know.
This is my first post here, so yeah. Thank you for your time.
Using a ray is not a good idea here since vision is not a laser, it’s a field, so you’ll want to use the dot product to check if the player vision is looking at the general direction of the scp.
local plr: BasePart = workspace.Plr
local scp: BasePart = workspace.Scp
local angleInRadians = math.acos(math.clamp(plr.CFrame.LookVector:Dot((scp.Position - plr.Position).Unit), -1, 1))
if angleInRadians > math.pi / 2 then -- Human's FOV is about 180 degrees