Hi guys,
I know that I should use pythagore to calculate the distance, but I need to calculate distance between 2 objectfs that are contained within 2 different movie clips.
Something in the line of :
xdist = Math.round(follow.p1._x - photo1_mc.p1._x);
ydist = Math.round(follow.p1._y - photo1_mc.p1._y);
distancefromthis = Math.round(Math.sqrt((xdistxdist) + (ydist ydist)));
But distancefromthis contains always the same value, maybe it’s because _x is calculated within the movie clip, so I need to find the photo1.p1._x in the stage.
Is it clear ?:pleased:
Thanks !
leraptor:
Hi guys,
I know that I should use pythagore to calculate the distance, but I need to calculate distance between 2 objectfs that are contained within 2 different movie clips.
Something in the line of :
xdist = Math.round(follow.p1._x - photo1_mc.p1._x);
ydist = Math.round(follow.p1._y - photo1_mc.p1._y);
distancefromthis = Math.round(Math.sqrt((xdistxdist) + (ydist ydist)));
But distancefromthis contains always the same value, maybe it’s because _x is calculated within the movie clip, so I need to find the photo1.p1._x in the stage.
Is it clear ?
Thanks !
try
StageCoords1:Object = (x:follow.p1._x , y:follow.p1._y)
StageCoords2:Object = (x:photo1_mc.p1._x , y:photo1_mc.p1._y)
follow.localToGlobal(StageCoords1)
photo1_mc.localToGlobal(StageCoords2)
then find the distance between StageCoords1.(x or y) and StageCoords2
You can use the movieclip method localToGlobal()
Here’s a simple example:
var p1 = {x:follow.p1._x, y:follow.p1._y};
var p2 = {x:photo1_mc.p1._x, y:photo1_mc.p1._y};
follow.localToGlobal(p1);
photo1_mc.localToGlobal(p2);
xdist = Math.round(p1.x - p2.x);
ydist = Math.round(p1.y - p2.y);
distancefromthis = Math.round(Math.sqrt((xdist*xdist) + (ydist*ydist)));
/Mirandir
YES !! This is perfectly working !
Thanks Joran420 ! Thanks Mirandir !