Be a Supporter!

movie clip face mouse

  • 263 Views
  • 4 Replies
New Topic Respond to this Topic
ConnorProgrammer
ConnorProgrammer
  • Member since: Mar. 7, 2009
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
movie clip face mouse 2009-03-09 14:29:08 Reply

can someone help me find the code so that when i move my mouse my movieclip faces it ?

StaliN98
StaliN98
  • Member since: Jul. 27, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to movie clip face mouse 2009-03-09 14:36:36 Reply

Use the atan2 function, which finds the angle based on the x and y difference between two points.

// mc is the name of the movie clip
function onEnterFrame(){
xdiff = _xmouse - mx._x; // Horisontal distance
ydiff = _ymouse - mc._y; // Vertical distance
angle = Math.atan2(ydiff, xdiff)/Math.PI*180; // Finds the angle in radians, which is converted to degrees.=
mc._rotation = angle;
}

Put it in the main frame's actions.

zuperxtreme
zuperxtreme
  • Member since: Jan. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to movie clip face mouse 2009-03-09 14:36:48 Reply

myMC._rotation = Math.atan2((_ymouse-myMC._Y),(_xmouse-my Mc._X))

Do that onEnterFrame or onMouseMove.

I recommend onEnterFrame, though.


BBS Signature
ConnorProgrammer
ConnorProgrammer
  • Member since: Mar. 7, 2009
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to movie clip face mouse 2009-03-09 15:43:33 Reply

does anyone know some code so that an enemy continuesly moves towards a player?

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to movie clip face mouse 2009-03-09 18:06:05 Reply

At 3/9/09 03:43 PM, ConnorProgrammer wrote: does anyone know some code so that an enemy continuesly moves towards a player?

AS: Movement - Basic
AS: Pointing/Shooting at Mouse
AS: Rotate and Follow Mouse by UnknownFury


- - Flash - Music - Images - -

BBS Signature