# MX random motion tutorial

**URL:** https://forum.kirupa.com/t/mx-random-motion-tutorial/14586
**Category:** flash
**Created:** [February 28, 2003, 2:06am UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586 "2003-02-28T02:06:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![feral](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@feral](https://forum.kirupa.com/u/feral)
#### Post date: [February 28, 2003, 2:06am UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586/1 "2003-02-28T02:06:45Z")

</div>

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(a_a+b_b));  
}  
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 🙂 Thanks!

Feral

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 28, 2003, 3:13am UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586/2 "2003-02-28T03:13:09Z")

</div>

Hi feral

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

yours  
Matze K.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 28, 2003, 4:23am UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586/3 "2003-02-28T04:23:13Z")

</div>

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

yours  
Matze K.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 28, 2003, 11:06am UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586/4 "2003-02-28T11:06:21Z")

</div>

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

pom :+)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 28, 2003, 4:27pm UTC](https://forum.kirupa.com/t/mx-random-motion-tutorial/14586/5 "2003-02-28T16:27:50Z")

</div>

So many resources. 🙂

yours  
Matze K.
