PDA

View Full Version : How to make a movieclip face another one?



Dancso
January 28th, 2008, 12:11 PM
Hi,

I'm working on a game in which i need help with making a movieclip face another one.
I have no idea how to get started with it.

Any ideas?

Marz
January 28th, 2008, 02:10 PM
Side Scroll, Iso Metric or Top Down Perspective?

ArmoredSandwich
January 28th, 2008, 02:49 PM
Hi,

I'm working on a game in which i need help with making a movieclip face another one.
I have no idea how to get started with it.

Any ideas?

http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary565.html

Dancso
January 31st, 2008, 10:16 AM
Top-down view.

I know about the command _rotation, but I don't have any good ideas on how could I make it face the other movieclip correctly.

Like, mc1._rotation = mc2._rotation wouldn't really work, like when the movieclips should face eachother, then it will just face away instead, and I've run out of ideas.

Of course, ingame, both movieclips should change position and rotation.

ArmoredSandwich
January 31st, 2008, 11:15 AM
Top-down view.

I know about the command _rotation, but I don't have any good ideas on how could I make it face the other movieclip correctly.

Like, mc1._rotation = mc2._rotation wouldn't really work, like when the movieclips should face eachother, then it will just face away instead, and I've run out of ideas.

Of course, ingame, both movieclips should change position and rotation.

Do you remember that math lessons when they explained tan, cos and sin? You'll need it now!

This is what you do:

xDistance = _root.mc1._x - _root.mc2._x;
yDistance = _root.mc1._y - _root.mc2._y;
radian = Math.atan2(xDistance, yDistance);
degrees = -(Math.floor (radian * (180/Math.PI)));

If you now set mc1._rotation = degrees, mc1 will face mc2. Do the same thing with mc2, or just set mc2._rotation = degrees - 180.

Just to be sure, here is the fla in which I tried it out.
http://www.wonima.demon.nl/other/Dancso_face_other_mc.zip