Let's say you make a movie in which each frame corresponds to one of your diagonal directions (each frame would contain a movieclip with a walk cycle of the man walking in the desired direction).
I've modified the order so that it will work with atan2 (0 degrees starts pointing to the right (3:00) and then proceeds clockwise).
1 * Right
2 * Down-right
3 * Down
4 * Down-left
5 * Left
6 * Up-left
7 * Up
8 * Up-right
Set up the movieclip so the crosshairs correspond to the 'center' of the man.
Put the movieclip on the stage, and call it man_mc.
Use the following script (attached to a frame on the main timeline) to control which frame to use.
code:
man_mc.stop();
man_mc.onMouseDown = function()
{
// dx,dy are the position of the mouse relative to the center of the man
var dx = this._xmouse;
var dy = this._ymouse;
// get the angle of the mouse
angle = Math.atan2(dy,dx);
// convert to a frame number (1-8)
frameNbr = Math.round(8+4*angle/Math.PI) % 8 + 1;
this.gotoAndStop(frameNbr);
// trace(angle + ", " + frameNbr);
}
Attached is a hastily-constructed sample movie that uses this script in the way that I describe. I'm using static pictures of the man, but instead, each frame of the man_mc movie should contain the animation you wish to use for that direction.




Reply With Quote