Random Motion

I am trying to make the movieClip named “fish” go to a randomly generated spot. I tried using the tutorial, but I didn’t understand the math, so I tried it with my own code. I’m not as much interested in getting this to work as I am knowing why it doesn’t work. So if someone could please explain why my code doesn’t work, I’d be very appreciative.


fish.onLoad = function() {
	generatePoint();
}
fish.onEnterFrame = function() {
	x = _x;
	y = _y;
	changeX = pointX-x;
	changeY = pointY-y;
	slope = changeY/changeX;
	goX = speed;
	goY = slope*speed;
	if(_x<pointX) {
		_x += goX;
	} else {
		_x -= goX;
	}
	if(_y<pointY) {
		_y += goY;
	} else {
		_y -= goY;
	}
	if(hitTest(pointX, pointY, true)) {
		generatePoint();
	}
}
function generatePoint() {
	pointX = random(Stage.width);
	pointY = random(Stage.height);
	speed = random(10)+1;
}

Thanks :thumb: