Hello. I am trying to make some movie clips do random movement with easing.
I have looked at the mouse follow with easing script here and have tried to adapt it so that it can choose a random x and y and go there.
I have seen the random movement script and I was going to use this and adapt it but I was finding it hard so i looked at the mouse follow with easing for some guidance and wondered why I actually need to calculate the distance, etc and why I can’t just make it so it doesn’t need to calculate the distances.
So I have made this code that to me seems fine but it doesn’t even do the random movement part. why not?
AS for the first frame in the as layer:
MovieClip.prototype.set = function()
{
width = 800; //movie width
height = 600; //movie height
this.speed = Math.random()*5+15; //Speed between 5 and 20
this.targx = Math.random()*width; //New X co-ordination
this.targy = Math.random()*height; //New y co-ordination
};
MovieClip.prototype.move = function()
{
if ((((this._x-this.targx)<10) || ((this.targx-this._x)<10)) && (((this._y-this.targy)<10) || ((this.targy-this._y)<10)))
{
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.set();
this.t = 0;
}
}
else
{
this._x += (this.targx-this._x)/this.speed;
this._y += (this.targy-this._y)/this.speed;
}
};
AS for the movie clip:
onClipEvent(enterFrame){
move();
}
Any ideas?
Thank you.