movie clip face mouse
- ConnorProgrammer
-
ConnorProgrammer
- Member since: Mar. 7, 2009
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
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
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
myMC._rotation = Math.atan2((_ymouse-myMC._Y),(_xmouse-my Mc._X))
Do that onEnterFrame or onMouseMove.
I recommend onEnterFrame, though.
- ConnorProgrammer
-
ConnorProgrammer
- Member since: Mar. 7, 2009
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
does anyone know some code so that an enemy continuesly moves towards a player?
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
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


