-
Senior Member
put in frame 1 main time line:
========= BEGIN CUT HERE =================
MovieClip.prototype.LookAt=function (x,y){
Xdiff = x-this._x;
Ydiff = y-this._y;
radAngle = Math.atan2(Ydiff, Xdiff);
this._rotation = radAngle*360/(2*Math.PI);
}
MovieClip.prototype.MoveTo=function (x,y,speed){
Xdiff = x-this._x;
Ydiff = y-this._y;
radAngle = Math.atan2(Ydiff, Xdiff);
this._rotation = radAngle*360/(2*Math.PI);
xx = Math.cos(this._rotation * math.PI / 180) * speed;
yy = Math.sin(this._rotation * math.PI / 180) * speed;
if ( Math.sqrt(xdiff*xdiff) >5 ){this._x +=xx;}
if ( Math.sqrt(ydiff*ydiff) >5 ){this._y +=yy;}
}
============== END ==============
HOW TO USE:
in a movie clip:
onClipEvent ( enterFrame){
this.LookAt (x,y);//give x and y here it could be like _root.anymovie._x,_root.anymovie._y or statick values.
this.MoveTo (x,y,speed);//same as above just give speed.
}
========= BEGIN CUT HERE =================
Movieclip.prototype.distance=function(clip1,clip2) {
Dx=eval(clip1)._x-eval(clip2)._x;
DY=eval(clip1)._y-eval(clip2)._y
return Math.floor(Math.sqrt (( DX*DX)+(DY*DY)));}
=========== END ==========================
use:
variable=this.distance ( clip1,clip2);
clip1 and 2 are the full path names for the clips.
onClipEvent ( enterFrame){dist=this.distance(this,_root.a2);}
MAD_SCI
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|