Kerryb3d Posted August 8, 2014 Share Posted August 8, 2014 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. Link to comment Share on other sites More sharing options...
amuseum Posted August 9, 2014 Share Posted August 9, 2014 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. Link to comment Share on other sites More sharing options...
BdR Posted August 9, 2014 Share Posted August 9, 2014 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. Link to comment Share on other sites More sharing options...
Sebi Posted August 9, 2014 Share Posted August 9, 2014 This is just a simple ellipse line intersection. http://mathworld.wolfram.com/Ellipse-LineIntersection.html Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 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 Link to comment Share on other sites More sharing options...
ssshenkie Posted August 10, 2014 Share Posted August 10, 2014 You could try something like this maybe?http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=move+towards+object.js&t=move%20towards%20object The only problem you will be facing then is that you need to set a custom boundry inside the eyeball. Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 Thought it'd be easier to demonstrate my cheaty way with a jsfiddle: http://jsfiddle.net/lewster32/nauxrq8t/ Mecha 1 Link to comment Share on other sites More sharing options...
Kerryb3d Posted August 10, 2014 Author Share Posted August 10, 2014 Wow, thanks guys! You've all been a tremendous help. Link to comment Share on other sites More sharing options...
Toninio78 Posted November 17, 2015 Share Posted November 17, 2015 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 Link to comment Share on other sites More sharing options...
Recommended Posts