hey im making a tactics game where you can walk with characters and trow things to eachother but i have a movieclip of a character and in that movieclip is the instance of the first frame 0moires, the second 30moires, the third 60moires till the twelfth frame is 330moires (moires is angle in degrees in greek) and in each frame you see the character from another position and now if you move with the mouse he turns to it and i want that if you click somewhere, the character moves to there and i already have an actionscript for it but it doesnt work, please look on it for if there are things that arent good and then tell the good script to me. moeko is the character and has 12 positions to look to.
_root.speed = 2;
// xmou and ymou are for that the character dont move imediatly to the mouse when the movie is loaded
xmou = _root.moeko._x;
ymou = _root.moeko._y;
// 2 arrays each with 8 values (degrees)
moires1 = [0, 22.6, 66.6, 111.6, 156.6, 202.6, 247.6, 294.6];
moires2 = [22.5, 66.5, 111.5, 156.5, 202.5, 247.5, 294.5, 340.5];
// a new array with the frame label names of the moeko movie
rotate = ["0moires", "30moires", "60moires", "90moires", "90moires", "120moires", "150moires", "180moires", "210moires", "240moires", "270moires", "300moires", "330moires"];
onEnterFrame = function () {
// the angle in radians between the clip and the mouse
radians = -Math.atan2(moeko._y-_root._ymouse, moeko._x-_root._xmouse);
// convert radians to degrees
degrees = radians*180/Math.PI+180;
// for i=0 and as long as i is not bigger than the array's length moires1 which is 8
for (i=0; i<=moires1.length; ++i) {
// if the value of the degrees variable is between moires1[i] and moires2[i]
// the caseTrue variable takes the value of the array rotate[i]
// ----------------
// for eg if degrees = 44 then 44 is between the value of the arrays
// moires1[2] and moires2[2] so caseTrue = rotate[2]
// rotate[2] = "45moires" that is why caseTrue is equal to "45moires"
// ----------------
// else if degrees is between 340.5 and 360 then caseTrue = "0moires"
if (degrees>=moires1[i] && degrees<=moires2[i]) {
caseTrue = rotate[i];
} else if (degrees>340.5 && degrees<=360) {
caseTrue = rotate[0];
}
}
// the following lines just tell the movie clip to move to, where the mouse was last clicked
while (j++, j<_root.speed) {
with (_root.moeko) {
_root.moeko._x += (xmou-_root.moeko._x)/18;
_root.moeko._y += (ymou-_root.moeko._y)/18;
}
}
j = 0;
};
onMouseDown = function () {
// xmou & ymou take the value of the x and y mouse position when you click it
xmou = _root._xmouse;
ymou = _root._ymouse;
// go to and stop in the frame with the same label name as the variable caseTrue
_root.moeko.gotoAndStop(caseTrue);
};