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);
}