A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Rotate two MC to face each other

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Posts
    104

    Rotate two MC to face each other

    Hi there,
    I have movie clips wondering the screen and when they come across each other they stop.

    But I would love them to rotate and face each other.

    any ideas anyone or examples
    cheers, stu
    Stuart

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    heres the code to make a clip point to another

    Code:
    onClipEvent(enterFrame){
    	xdiff = _parent.pointToClip._x - _x;
    	ydiff = _parent.pointToClip._y - _y;
    	_rotation = Math.atan2(ydiff, xdiff) * 180/Math.PI;
    }
    and here is a (Romeo Must Die-esque) example
    Attached Files Attached Files

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    104
    works a treat on two set mC clips...
    I also need to work out or find help on:
    the screen is filled with mc's so when they bnag into each other i need them to rotate towards each other.

    How do I find out what the name of the one it has bump into?

    here's the code that looks to see if they have collided:
    posX = new Array();
    posY = new Array();
    //random rotate
    rotate = new Array(45, 90, 270, 180, 135, 315, 225, 45);
    // gangA
    gangAhit = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

    //
    function updateArrayA() {
    for (i=0; i<gangAhit.length; i++) {
    for (j=0; j<gangAhit.length; j++) {
    if (i != j) {
    if ( gangAhit[i]!= 2 && gangAhit[j]!=2){
    if (Math.abs(posx[i]-posx[j])<20) {
    if (Math.abs(posY[i]-posY[j])<20) {
    if (i<8 && j<8) {
    gangAhit[i] = 1;
    gangAhit[j] = 1;
    a = random(8);
    _root[i]._rotation = rotate[a];
    _root[i]._x += random(5)-1;
    _root[i]._y += random(5)-1;
    } else if (i>7 && j>7) {
    gangAhit[i] = 1;
    gangAhit[j] = 1;
    a = random(8);
    _root[i]._rotation = rotate[a];
    _root[i]._x += random(5)-1;
    _root[i]._y += random(5)-1;
    } else if (i<8 && j>7) {
    gangAhit[i] = 2;
    gangAhit[j] = 2;
    _root[i].gotoAndPlay(10);
    _root[j].gotoAndPlay(10);
    } else if (i>8 && j<7) {
    gangAhit[i] = 2;
    gangAhit[j] = 2;
    _root[i].gotoAndPlay(10);
    _root[j].gotoAndPlay(10);
    }
    } else
    {

    }
    }
    }
    }
    }
    }
    }

    Thanks again for your help.
    stu.
    Stuart

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