Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a staring eye with limited rotation?

Asked by 6 years ago

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?

0
Oh ,these eyes that I remember from the 2009-2011. They were creepy models... LordTechet 53 — 6y
0
So, any answers? Konethorix 197 — 6y
1
Sadly, I cannot help you with it, I can tell you need CFrame and rotation from X angle LordTechet 53 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

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? Konethorix 197 — 6y
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. mattscy 3725 — 6y
0
Is there any way to make the eye go back to it's original rotation when you go out of range? Konethorix 197 — 6y
0
Edited again, you can try that. mattscy 3725 — 6y
Ad

Answer this question