I figured out how to make an NPC's head turn towards another object, but it looks weird when the target object moves behind the NPC and the head goes into impossible positions and it looks creepy. How can I find the angles of where the head is facing so I can manipulate those angles into rotational restrictions?
local bg = script.Parent:WaitForChild("BodyGyro") local head = script.Parent while wait(0.5) do -- loop the movement -- maybe do some type of check before proceeeding and facing towards the target??? bg.CFrame = CFrame.new(head.Position, Vector3.new(workspace.Lobby["Police Chief"].Head.Position.x, head.Position.y, workspace.Lobby["Police Chief"].Head.Position.z)) -- pretty much just makes the head look towards a police chief's (head). end
Very simple script here, speaks for itself
the head's CFrame's lookVector, or just
(head.Position - Vector3.new(workspace.Lobby["Police Chief"].Head.Position.x, head.Position.y, workspace.Lobby["Police Chief"].Head.Position.z)).unit
will tell you the direction. As this is a unit vector it is normalized to length 1. So that means, just get the component that is 'behind' and draw a threshold.
For example, if the policeman faces the x direction, then just make sure the x-component of the lookvector is >-0.2 or something. A lookvector x-component of 1 then means looking forward, -1 looking backwards.
Does this answer your question? I would use this method over using basePart.Orientation
while true do print(head.Orientation.Y) wait(0.1) end