I’m relatively new to flash, and am trying to figure out a way for a character’s eyes to follow the curser.
I’ve attached the swf of my character (A****aka from Princess Mononoke).
I understand the simple mouse follow, but I don’t want his eyes leaving their sockets to chase after the cursor. :o
Is there a way that I can set a boarder so that the eyes stay within a certain area, but are drawn (within that area) towards the cursor?
His eyes (together) are one symbol. I want them to both follow the mouse, but not go cross-eyed. Know what I mean?
Thanks lostinbeta, sorry for not catching that before. =)
Hmm… actually, that’s not quite what I need. Eki demonstrated how to make an object rotate in the direction of the cursor, but that’s not the same as following it. I think he was onto it at first with his if(eye.hitTest(eyeCavity)) suggestion, but I’m not sure how to implement that.
(If it only rotates, than it will never look “forward” again, only off towards the outside).
I think I’ll use easing combined with the function, but my first priority is to get the mouse-follow working. :hangover:
Well you can use easing and just use if statements to tell it to stop moving, but that only allows you an invisible box, so the pupil of the eye may still get out of view.
Which was a straight forward mouse follow with easing. Then I was trying to figure out how to incorporate if(eye.hitTest(eyeCavity)), but wasn’t quite understanding that line of code.
What you just said makes sense to me though, so I’ll try that first.
Check the _x and _y coordinates compared to the centerX and centerY variables. If the _x position is 20 pixels to the left or to the right of the center point it will stop there, and if the _y position is 20 pixels above or below the centerpoint it will stop there.
Hey, thanks a lot for all your help! I’ve visited Kirupa.com often for tutorials and such, but this was my first time visiting the forum. I’m very impressed with the quick and accurate response/help.
Ooooppps, sorry about the no semi-colon in line 19…lol. I really can’t believe I did that, it is natural for me to add semi colons now. Hmmm, maybe because it was like 3am when I was helping you…lol.
That is a really cool result! I really wasn’t sure my code would work as I was just winging it and going by theory really. My code is usually wrong when I do that.
I am glad you enjoy it here at kirupaforums… I have been an addict from the day I signed up!!!
Ok… now just for a little note… you can use variables to set the distance. So this line centerX-10 could become centerX-distX and in the onClipEvent(load) you can have the variable distX = 10
It would make for easier updating if you ever have to use this code in the future.
Heh. Don’t worry about the ; I was just buggin’ ya!
My prof used to haras us if we ever forgot to use 'em.
I’ve taken 4 years of University, mostly in Computer Science and Commerce, but it’s been almost 3 years since I’ve done any coding and I’m a little rusty.
Yeah, I am sure if I went to school for it I would get in trouble a lot :P…lol… j/k. Actually I don’t usually forget semi colons, I got so used to needing them there in Javascript (learned that before AS) or I would get an error that now I tend to type them in without realizing it. PHP is really picky about them too, your whole script relies on 1 semi-colon, man I hate that…lol. I just started PHP and when I get fatal errors I hate scanning my script for one tiny mistake. At least Flash isn’t so picky, you can leave it out and it doesn’t care.