MX random motion tutorial

Hey guys and gals,

So I started folling around with the MX random motion tutorial, and I really like it. I would like to take it a few steps further. I’m rather new to raw actionscripting so I have no good idea how to code this on my own. Anyway, this si the code I have now:

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(aa+bb));
}
MovieClip.prototype.reset = function() {
//specify the width and height of the movie
width = 550;
height = 400;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*1+0;
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>0) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};

This what I want to do:

  1. Eliminate the small pause each object makes before it begins moving in a new direction.
  2. Instead of moving in a straight line from point A to point B, I want each object to kinda move around more naturaly, adding in gradual arcs and turns and what not.
  3. I want the objects to bounce of each other
  4. I want the objects themselves to scale by their X and Y values.

I’m probably biting off more than I can chew with this one… but any help will be greatly appreciated :slight_smile: Thanks!

Feral

Hi feral

Maybe this will help you - it’s one of my old Flash 5 collision experimental. I will update it soon. :slight_smile:

yours
Matze K.

I updated the script - now it’s mx compatible. :slight_smile:

yours
Matze K.

You can also check the Useful tutes thread in the Best of Kirupa section.

pom :+)

So many resources. :slight_smile:

yours
Matze K.