Making eyes follow the cursor [FMX]

Hey all… this may seem like a pretty stupid question, so pardon me, but I’m pretty much brand-new to Flash and ActionScript (minus the Tutorials included with it I’ve taken).

Anyways… I know how to make something follow the cursor (e.g. a ball that moves where your cursor does). However, I’m having a lot of trouble figuring out how to do what I need to for an animation, namely make eyes follow a cursor.

Here’s the situation: I need to make a graphic (the eye in the middle of the eyeball) follow the cursor (i.e. look up, look left, look in any number of diagonal directions) depending on where the user moves the cursor. But the eyes, obviously, need to stay put in one static spot and move in a very limited region (the entire white part of the eye, but not beyond it).

Furthermore, the eyes start out staring at the user. How do I additionally make them dart to the edges where they’ll be looking around once the cursor is moved?

Does anyone know how I can do this?

Thanks so much for your time!

  • andrew kugelstadt

Hi,

You already know the answer:

move in a very limited region

Use

if(eye.hitTest(eyeCavity))

Cheers

SHO

Thanks for trying to help me, but alas, I’m afraid I’m too much of a novice to use your advice properly :frowning:

Should I be using the StartDrag command for this? Because the eye seems to move a set distance from the cursor while following it, instead of rotating to follow the cursor from a fixed point. Argh! I hate being ignorant :frowning:

Anyways… here’s my .fla file, too, so everyone can scream “NO, YOU BUFFOON!” and save the day for me :slight_smile:

Hi,

this file uses a different approach.

Cheers

SHO

Wow! That works great. Thanks so much for your help!

Sadly, I stare at the code and I am just totally clueless… if it’s not too much trouble, would you mind explaining to me how you came up with that?

Then again, if that’s too annoying or you’re busy, don’t worry about it.

Thank you again!

-wobbly

well im not too hot on my trig skills considering i havent taken that class… but the first line calculates the rotation with a tangent thingy… ( i learned soh cah toa in geometry last year ) and then it applys the rotation to the pupil of the eye…

also, notice how he moved the center point of the pupil off to the side so it will rotate around the center of the eye… so its rotating around that fixed point

Hi,

Yes Scootman, that’s absolutely right.

Sorry WobblyFork I haven’t answer before but I’m really busy.

Glad it did what u wanted.

Cheers

SHO