I got this code on these forums. I use it for moving a movieclip at random directions inside a given boundary.
I would like to add a speed variable cuz I think it moves to fast as it is now at my framerate.
Can anyone help me with that ?
Code:
onClipEvent (load) {
//define direction function
function changeDirection(){
this.dx = Math.random()*2-1;
this.dy = Math.random()*2-1;
}
// set boundaries
this.xMax = this._x+60;
this.xMin = this._x;
this.yMax = this._y+20;
this.yMin = this._y;
}
onClipEvent (enterFrame) {
//if at boundaries, invert direction
if(this._x + this.dx > this.xMax || this._x + this.dx < this.xMin){
this.dx = -this.dx;
}
if(this._y + this.dy > this.yMax || this._y + this.dy < this.yMin){
this.dy = -this.dy;
}
this._x += this.dx
this._y += this.dy
if (Math.random()>.9) {
changeDirection();
}
}
Thanks...