How can I make eyes follow my cursor?

Hey dev forum, I’ve ran in to a problem that I can’t fix on my own. I need these eyes, (which are made out of two guis, one for the white and another for the pupil) specifically the pupil to face my mouse wherever it goes, and also stay inside of the white part of the eye. I have been searching for a solution for a while now, but I couldn’t find anything, the closest I got had a bug with the GuiInset that wasn’t explained. I put pictures below to show what I need.


Thank you for your help!

1 Like

Something like this, if you can make sense of it!

Yeah… I have no idea what any of that means, can you explain it please?

The righthand pupils distance from the righthand side of the eye is the equivalent percentage to the cursors distance from the righthand side of the screen, but you have to take into account the padding between the edges of the eyes horizontal size and the cursors horizontal screen size (yellow squiggles). And also you have to account for the size of the nose from the center of the screen (blue squiggles). I only included the adjustments to horizontal movements in my image, the same adjustments must be made for the vertical movements of the mouse.

If you know the percentile size difference to map from and to then a generalised form is this:

((MAX - MIN) * PERCENT) + MIN

To calculate the new X position in the eyes (from the old position on the screen) then the form is:

OLD PERCENT = (x - OLD MIN) / (OLD MAX - OLD MIN)
NEW X = ((NEW MAX - NEW MIN) * OLD PERCENT) + NEW MIN

Where OLD_MIN is the screen minimum, OLD_MAX is the screen max, NEW_MIN is the eye min, and NEW_MAX is the eye max.

These will not account for padding or a big bit of the middle being out of bounds (i.e. the nose). And the units for both OLD and NEW must be the same.

1 Like

So from what I got, I made this model (ignore the white I made a mistake) :

With the navy blue representing the new min, and the maroon representing the new max, and using a render-stepped function, update them every frame? Or am I still not getting it?

Actually, forget that last post, I made that one late at night. After a lot of testing I got the percent values to line up pretty close (around a 2% difference, which I can assume is the nose gap you were talking about earlier) Anyways, I have both of the percents, but I don’t know how to move the eye to that position
image

That is my code so far.

Thank you for all of your help!

Nevermind lol, I figured it out thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.