A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] 360 rotation by increments

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    146

    [F8] 360 rotation by increments

    I'm trying to rotate a movie clip. Simple enough?

    Code:
    			dpx = _x-destx;
    			dpy = _y-desty;
    			distance = Math.sqrt(Math.pow(dpx, 2)+Math.pow(dpy, 2));
    			angle = Math.round(180*Math.atan2(dpy, dpx)/Math.PI)-90;
    			if (angle>180) {
    				angle -= 360;
    			} else if (angle<-180) {
    				angle += 360;
    			}
    			if (_rotation<angle) {
    				_rotation+=rot;
    			} else if (_rotation>angle) {
    				_rotation-=rot;
    			}
    rot is the increment that I want the MC to rotate at. it equals 1 at present. destx and desty are the destination x,y coordinates of my MC.

    I'm having a hard time explaining this. The MC needs to be able to rotate to angle using the increments, but as we all know, _rotation goes from -180 to 180. Therefore, the MC rotates allllll the way back around (ie, it doesn't rotate the shortest distance) to get to the opposite "side."

    I want this because I don't like that my MC would instantly jump to whatever angle the destination is at and then move. It's for aesthetics. I just need another brain to help me think about this.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I normally convert all the angles between 0 and 360 degrees. Now find 2 destination angles:

    dist1 = Math.abs(angle - _rotation)
    dist2 = 360 - dist1

    If(dist1 < dist2){
    //turn toward angle
    }else{
    //turn toward angle+360
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center