hi all,
hopefully can either show me or point me in the right direction of an explanation of how to do the following…
i have a number of duplicated mc’s that move around the stage at random - i also have an mc that sits in the middle of the stage this mc has the name of “area” - at present the random moving mc’s use hittest to change the frames within the moving mc’s from frame 1 to frame 2 and then jump back to frame when the moving mc leaves the “area” mc.
this all works great.
but what i want to do now is (hopefully) just edit the hittest command within the moving mc’s to make the moving mc’s actually bounce off the “area” mc.
here is the hittest script that sits within the moving mc’s…
this.onEnterFrame=function(){
if(this.hitTest(_root.area)){
gotoAndStop(2);
} else {
gotoAndStop(1);
}}
is there a simple way of telling the mc’s that when they hit the “area” just change direction?
or would i need to do that in the controlling random movement script as shown below?
function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(a*a+b*b));
}
MovieClip.prototype.reset = function() {
//specify the width and height of the movie
width = Stage.width;
height = Stage.width;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*25+2;
this.targx = Math.random()*width;
this.targy = Math.random()*height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;
};
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
hope someone can put me right
thanks in anticipation