Specifically, I'm trying to have a character whose eyes follow the cursor. I have the pupils as separate objects laid over the eye whites, and I want to achieve the effect of the eyes darting around by having the pupils move toward the mouse cursor but not past the edge of the eyes.
I was almost able to get the effect I want by pinning the pupils rope-style to the centers of the eyes and lerping them toward the cursor but that wasn't as dynamic as I need it to be, since the eyes aren't perfect circles and it doesn't hold up if the character changes size.
Does anyone have advice?
Develop games in your browser. Powerful, performant & highly capable.
I gave it a try...
every tick I calculate the distance the mouse is from the middle of the face - between a max of -100% and +100% in both x and y axis, then move each eye that percentage of the max distance it is allowed to move.
the face is a container, that has the face, a left and right eye, and an eye background. That allows for multiple faces to be on the screen at once, and each set of eyes gets set based on where the face is in relation to the mouse...
the faces have drag and drop so you can move them around. add a face by pressing Z, delete a random face by pressing X, change the scale of each face to a random value between 50% and 200% by pressing Space.