A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Group of movieclips avoiding each other via rotation?

  1. #1
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191

    Group of movieclips avoiding each other via rotation?

    I am trying to accomplish something similar to the map icons in Sims 3, where you have little clips that avoid each other but stay rotated around a static point.


    I am trying to use atan2 to accomplish this but I don't think I have it correct.

    Here is my current code (AS2 at the moment, until I get a chance to upgrade from F8):

    Code:
    import flash.geom.Point;
    
    var tags:Array = [tag01, tag02, tag03];
    
    _root.onMouseUp = function()
    {
    	tag01._x = _xmouse;
    	tag01._y = _ymouse;
    }
    
    this.onEnterFrame = function()
    {
    	var clip1:MovieClip;
    	var clip2:MovieClip;
    	
    	for(var i:Number = 0; i < tags.length; i++)
    	{
    		for(var j:Number = 0; j< tags.length; j++)
    		{
    			if(tags[j] != tags[i])
    			{
    				clip1 = tags[i];
    				clip2 = tags[j];
    				
    				var coord:Point = localToLocal(clip1, _root, {x:clip1.head._x, y: clip1.head._y});
    				
    				var coord2:Point = localToLocal(clip2, _root, {x:clip2.head._x, y: clip2.head._y});
    				
    				var rot:Number = Math.atan2(coord2.y-coord.y, coord2.x - coord.x)/Math.PI*180;
    				
    				clip1._rotation = rot;
    			}
    		}
    	}	
    }
    
    function localToLocal(containerFrom:MovieClip, containerTo:MovieClip, origin:Object):Point
    {
    	var point:Object = origin == undefined ? {x: 0, y: 0} : origin;
    	containerFrom.localToGlobal(point);
    	containerTo.globalToLocal(point);
    	
    	return new Point(point.x, point.y);
    }
    i'm obsessed with video games.

  2. #2
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191
    anyone?
    i'm obsessed with video games.

  3. #3
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    I've never seen or played sims 3, so I am not really sure what you are trying to get here, heh.

    The only movement I see is rotation, so I would guess you are trying to rotate a few mcs out of each other's way? Do you have a registration point that is some distance away from the clips?

    Maybe if you could supply a stripped down fla?

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