Eye Following Pointer

Recommended Posts

Hello, I'm currently trying to do a simple eye movement that follows the pointer.   Setting the pupil to track the pointer is easy enough, but I can't seem to find the best way to keep the pupil inside the bounds of the eye, while respecting the curvature of the eye.  Below is an example of the eye shape.

Any input would be greatly appreciated! Thank You.

Share on other sites

pick a point as the center of the eye. find a line from the center to the cursor, and the point where the line interscets the boundary of the eye. check that the pupil doesn't pass this point.

Share on other sites

Do the eyes need to be oval shaped?

Maybe it's better to keep it simple and have the eyes be circle shaped. Alternatively, you could have the eyes any shape but still have the pupils only move in a perfect circle within the confines of the eyes.

Share on other sites

This is just a simple ellipse line intersection.

Share on other sites

The way I'd do this is cheat. I'd make this circular and put the pupil as a child of the eyeball sprite, then borrow from any number of tutorials or existing examples of this type of effect. Then I'd set the x scale of the whole sprite to 0.75 or so, and rotate it -20 degrees. The pupil will take on the same distortion as the eyeball, but I think that's a small price to pay compared to the maths involved in constraining something to a rotated oval shape

Share on other sites

Wow, thanks guys!  You've all been a tremendous help.

Share on other sites

• 1 year later...

Thought it'd be easier to demonstrate my cheaty way with a jsfiddle: http://jsfiddle.net/lewster32/nauxrq8t/

Hello,

I just try this url, but it doesn't work well actually.

I tried to find a way to fix it but I can't  ;-)

Could you take a look ?

Thanks