A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Repulsion between various mc's

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    17

    Repulsion between various mc's

    Hello, I'm trying to do that, four mc's that I have on stage that have a startDrag effect, have repulsion between them to avoid that they overlap each other. I'm trying this:

    Code:
    addEventListener(Event.ENTER_FRAME, avoidTouch);
            var thresh:Number = 1111;
    		function avoidTouch(event:Event):void {
    			  
    			  var distx: int = menu.b1.x - mouseX;
    			  var disty: int = menu.b1.y - mouseY;
    			  var dist:Number = Math.sqrt(distx*distx + disty*disty);
    			  trace (dist);
    			  if(dist < thresh){
    					menu.b1.x = mouseX + thresh*distx/dist;
    					menu.b1.y = mouseY + thresh*disty/dist;
    			 }
    		}
    But it only works with the mouse and I want to do with mc's.

    Someone could tell me if there is another solution for this.

    Thank you.

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    if there is another solution for this
    what about you creating that solution that can solve your problem, right?

    hint: what would happen if you replace mouseX with yourMovieClip.x ?
    who is this? a word of friendly advice: FFS stop using AS2

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