So I used CFrame.new(the eye's position, the torso's position) to make the eye 'stare' at the player but I want the eyes to have limits, if you stand behind the eyes they won't be able to look at you. So how?
Making a staring eye with limited rotation?
1 answer
You could try something like this:
local min = -90
local max = 90
while wait() do
local cf = CFrame.new(eye.Position,torso.Position)
local angles = {cf:toEulerAnglesXYZ()}
local newAngles = {}
for i,v in pairs(angles) do
if math.deg(v) < min or math.deg(v) > max then
newAngles = {0,0,0}
break
else
newAngles[i] = v
end
end
eye.CFrame = CFrame.new(eye.Position) * CFrame.Angles(unpack(newAngles))
end
Not sure if toEulerAngles returns radians or degrees, so you might have to use math.rad on the new angles, but something like this might work.
4 comments
I haven't tried this out yet until today and from what I found out is that the 'v' in the loop are actually really small numbers, and in an if statement, you said that 'if v > 90 then', which is impossible to happen. Is there any other way to do this?
Yeah, I figured it might be in radians instead of degrees, a quick math.deg should do the trick. I've edited the script, hopefully this works.
Is there any way to make the eye go back to it's original rotation when you go out of range?
Edited again, you can try that.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Oh ,these eyes that I remember from the 2009-2011. They were creepy models...
So, any answers?
Sadly, I cannot help you with it, I can tell you need CFrame and rotation from X angle