The object that the ray is being fired out of is constantly rotating. What I'm trying to do is to find the angle between the direction the object is facing and the direction of the ray being fired. What I tried to do is subtract the direction of the ray from the object's look vector, but that didn't really work. Here's my script:
local Camera = script.Parent
local ignorelist = {script.Parent.Parent.Parent}
while wait() do
for i,v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local head = v:FindFirstChild("Head")
if human and head then
if (Camera.Position - head.Position).magnitude < 40 then
NewRay = Ray.new(Camera.Position, (head.Position - Camera.Position))
local Angle = NewRay.Direction - Camera.CFrame.LookVector
local Hit = workspace:FindPartOnRayWithIgnoreList(NewRay, ignorelist)
if Hit then
if Hit.Parent.Name == "Guard" then
----- guard input
else
if Hit.Name == "Head" then
print(Angle)
end
end
end
end
end
end
end
Thanks.

1 comment
welcome to the world of trig xd