PDA

View Full Version : unessary spinning



radi
October 9th, 2010, 02:18 AM
in a circle how can i tell what is the shortest path

if (team1[h].rot > cursorDegree - 90)
{
team1[h].rot = team1[h].rot - 20;
}
if (team1[h].rot < cursorDegree - 90)
{
team1[h].rot = team1[h].rot + 20;
}

this works unless the number jumps the 0/360 gap then it will require a full counter clockwise run im wondering what i need to add to this for a more intelligent rotating of a movieclip , thanks for your help :)

bluemagica
October 9th, 2010, 10:28 AM
if((a.rot-b.rot)<180)
{
rot++;
}
else
{
rot--;
}

radi
October 9th, 2010, 03:20 PM
if ((team1[h].rot - (cursorDegree-90))<360)
{
team1[h].rot = team1[h].rot + 10;
}
else
{
team1[h].rot = team1[h].rot - 10;
}
if i understood you right, this still causes spinning

Gathan
October 10th, 2010, 11:33 PM
This would be a generalized test to determine which rotation direction the movieclip should go in to move towards facing the mouse.

First store both the radians for the movieclip rotation and the cursor

rad1 = mcrotation*3.14/180
rad2 = atan2(mousey-mcy, mousex-mcx);

Then plot two different points that are close to the starting place to figure out which one is closet and store the mouse location to

p1 = new point(cos(rad1+0.0001), sin(rad1+0.0001));
p2 = new point(cos(rad1-0.0001), sin(rad1-0.0001));
p3 = new point(cos(rad2), sin(rad2));

Measure the angle between the two different points and the mouses location

angle1 = acos(pt1.x*pt3.x+pt1.y*pt3.y);
angle2 = acos(pt2.x*pt3.x+pt2.y*pt3.y);

Lastly two statements, one is less than the other, that'll tell us which direction to rotate the movieclip in.

if (angle1<angle2) {
mcrotation += 5;
}
if (angle2<angle1) {
mcrotation -= 5;
}

radi
October 12th, 2010, 07:49 AM
thanks, this worked