Hi Guys,
Does anyone know how to change the below code to only move randomly along the _x axis and NOT the _y axis?
I’m not sure what to change…
Thanks so much.
//Random Movement: kirupa.com
//Thanks to Suprabeener for the original code!
function getdistance (x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (hyp(run, rise));
}
function hyp (a, b) {
return (Math.sqrt(aa+bb));
}
MovieClip.prototype.reset = function () {
var dist, norm, movie_height, movie_width;
// movie_height: refers to the height of your movie
// movie_width: refers to the width of your movie
//---------------------------------
movie_height = 550;
movie_width = 400;
//---------------------------------
speed = Math.random()4+2;
targx = Math.random()(movie_width-_width);
targy = Math.random()*(movie_height-_height);
dist = _root.getdistance(_x, _y, targx, targy);
norm = speed/dist;
diffx = (targx-_x)*norm;
diffy = (targy-_y)*norm;
};
MovieClip.prototype.move = function () {
var cycle;
// cycle: specifies speed of the movement. The smaller
// number, the faster the objects move.
//--------------------------------------------
cycle = 100;
//--------------------------------------------
if (_root.getdistance(_x, _y, targx, targy)>speed) {x += diffx;y += diffy;
} else {x = targx;
y = targy;
if (!this.t) {
t = getTimer();
}if (getTimer()-t>cycle) {reset();
t = 0;
}
}
_x = x;
_y = y;
}