Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a staring eye with limited rotation?

Here's the illustration

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?

3 comments

0

Oh ,these eyes that I remember from the 2009-2011. They were creepy models...

0

So, any answers?

1

Sadly, I cannot help you with it, I can tell you need CFrame and rotation from X angle

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

0

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?

0

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.

0

Is there any way to make the eye go back to it's original rotation when you go out of range?

0

Edited again, you can try that.

This discussion is preserved as it was. New answers, comments, and votes are closed.