I’m trying to make a movieclip push out from the center of the stage, but I’m having a problem with the math.
I made an function, but it pushes out in a diamond shape.
function newCords(newX:Number, newY:Number, distance){
var centerX = Stage.width/2;
var centerY = Stage.height/2;
var slope;
newX-=centerX;
newY-=centerY;
if(newX>0 && newY>0){
slope = (newY)/(newX);
trace("Slope: "+slope);
newX = distance/(Math.sqrt(1+slope));
newY = slope * newX;
newX+=centerX;
newY+=centerY;
}else{
if(newX<0 && newY<0){
slope = (newY)/(newX);
newX = distance/(Math.sqrt(1+slope));
newY = slope * newX;
newX= centerX-newX;
newY= centerY-newY;
trace(newX);
}else{
slope = -(newY)/(newX);
if(newY<0){
newX = distance/(Math.sqrt(1+slope));
newY = slope * newX;
newY = -newY;
}
if(newX<0){
newX = distance/(Math.sqrt(1+slope));
newY = slope * newX;
newX = -newX;
}
newX+=centerX;
newY+=centerY;
}
}
return ([newX, newY]);
}
////// to test the function... you will see that it moves in a diamond shape
point1.onEnterFrame = function(){
centerPoint._x = Stage.width/2;
centerPoint._y = Stage.height/2;
var tempArray = newCords(point1._x,point1._y, 100);
point2._x = tempArray[0];
point2._y = tempArray[1];
}
point1.onMouseDown = function(){
startDrag(this);
trace("click");
}
point1.onMouseUp = function(){
stopDrag();
trace("click");
}