PDA

View Full Version : Making eyes follow the cursor [FMX]



WobblyFork
November 14th, 2002, 09:22 PM
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

eki
November 15th, 2002, 06:19 AM
Hi,

You already know the answer:


move in a very limited region

Use


if(eye.hitTest(eyeCavity))

Cheers

SHO

WobblyFork
November 15th, 2002, 10:17 AM
Thanks for trying to help me, but alas, I'm afraid I'm too much of a novice to use your advice properly :(

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 :(

Anyways... here's my .fla file, too, so everyone can scream "NO, YOU BUFFOON!" and save the day for me :)

eki
November 15th, 2002, 11:32 AM
Hi,

this file uses a different approach.


Cheers

SHO

WobblyFork
November 15th, 2002, 05:26 PM
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

Scootman
November 17th, 2002, 10:03 PM
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

eki
November 19th, 2002, 06:09 AM
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

rgpg
November 15th, 2004, 10:34 PM
Hi,

this file uses a different approach.


Cheers

SHO
Hi,

This message did not have an attached source code or a link to it...is it still available somewhere? (I'd like to build an "eyes-follow-cursor" effect too) :cons:

Thanks.

RGPG

chu_chin
November 18th, 2004, 11:28 AM
try using

this.startDrag(true)

make the cursor follow the object's registration point. (so check ur registration point first, see if it's in the spot u want)

hope this helps

rgpg
November 18th, 2004, 01:24 PM
try using

this.startDrag(true)

make the cursor follow the object's registration point.

Thanks for the pointer. I was trying to get the .FLA file with sample code that apparently was posted on this thread before (that I can't see as an attachment).

Thanks again,

RGPG