Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Random Motion



Hi all

here is a bit of actionscript I got from a tutorial at gotoandlearn which causes the ball movie clips to move around randomly. if you want to try itself just create a MC with a graphic in and make sure export for actionscript is selected under linkage(in the library) and give it an identifier of ball.

So the problem is that if I lower the speed at which the balls move around, which I do by changing the code this._x += (this.dx - this._x) / 8; to
this._x += (this.dx - this._x) / 25; then eventually all movement stops.

Any ideas why and how to prevent it from doing that?

here is the code:

for(i=0;i<20;i++){
var t = this.attachMovie("ball","ball"+i,i);
t._x = Math.random()* Stage.width;
t._y = Math.random()* Stage.height;
t.dx = Math.round(Math.random()* Stage.width);
t.dy = Math.round(Math.random()* Stage.height);
t._xscale = Math.random()* 20+80;
t._yscale = t._xscale;
t.onEnterFrame = mover;
}

function mover(){
this._x += (this.dx - this._x) / 8;
this._y += (this.dy - this._y) / 8;
if (Math.round(this._x) == this.dx)
{
this.dx = Math.round(Math.random()* Stage.width);
this.dy = Math.round(Math.random()* Stage.height);
}

}



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 09-05-2006, 02:00 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Random Motion Along Specified Paths At Random Intervals?
I am working on a site right now and I have a collaged background image with a faded ciruit board looking series of intersecting lines.

I would like to create a subtle gradated sphere to simulate a signal travelling along the cicuits. However, I would like several instances of the signal (or pulse) to take different routes and begin and end randomly.

Is there a way to set-up possible routes with a motion guide and then tell objects to randomly choose those routes at random intervals???

Random Paths (NOT Random Motion)
I only know the basics in Flash so I'm not quite sure how to word this..
Say I've got one linear motion guide that then splits in three directions. I'd like my movie clip to travel on the path and then randomly choose which of the three paths to take. I have no idea where to begin and have searched for scripts - only random motion scripts have popped up through. Hopefully, in the end, I'd have multiple objects travelling on random paths - similar to this - http://www.flashkit.com/movies/Scrip...1926/index.php.
Thanks in advance.

Random Motion
Need to create randomly moving object, not jerking though... Say, dog. Need script. Anybody, help... Please!
Will appreciate if you e-mail me to: dedbabay@aol.com

Random Motion
Hi all,
I am trying to modify one of the "action script tutorials" from Kirupa; it's called random motion. (http://www.kirupa.com/developer/actionscript/random.asp)
I am trying to modify it, so when the user roll over on one of the moving graphics, that particular one will stop, and when the user roll off on it, it will start moving again.
Anyway, I hope some one knows! Thanks a lot!!!!!!!!!!!!!!

Wa ha ha ha

Random Motion And More
Hello all,

Okay here is my problem. Say I have these letters spelling out a word. Each letter is a mc. Now I want these letters to move randomly over the screen. I also want them to every so often return to their original position and form the word. How would iz go about doing something like that.

Thanks.

Random Motion
Hi (again)
Can anyone tell me how i can duplicate a movie clip and place it at random places along the 'x' axis so that they then fall to the bottom of the screen individually of each other (i know how to make them fall). I use this script (below) to duplicate the movie clip but the movie clip just randomly flashes around the screen and dont fall individually of each other (they fall as a group).

increment = 0;
while (increment<=30) {
duplicateMovieClip("apple", "apple"+increment, increment);
increment = ++increment;
}
stop();

This script (above) is on the main timeline and inside the movie clip itself i have this script (below). I cant work out this random script to stop the movie clip from flashing around the screen.

this._x = this._x + (Math.random()*8)- 4;
this._y = this._y + (Math.random()*6)- 3;

I'm not to sure how this works or why the movie clip just flashes around the screen. I want it so that the movie clip appears on the screen and then falls to the bottom (but i think that i can work out the falling part).

Any ideas? I have no idea about this
Thanks anyway!! (this is really killing me)
(i havent put the falling script in yet)

[F8] Random Motion
hi

Doea anyone know how to create a smooth random motion with the object keeping the right orientation (allways 'looking' forward)?

I'm using FuseKit by the way ..

Random Motion
i`ve made a random motion code, and added it to a MC. but when i duplicate MC a problem occurs. all duplicated MCs move randomly, but only for some time, afther that all, but one, move to (0,0).
why`s that??
look at .fla file

Random Motion
Hi all. Can somebody point me in the direction of a tutorial or some help to do with random triggering of movies? I have a small landscape and various little clips of events happening on the landscape, I need the events to happen at random times in no particular order. Does anyone know of a tutorial, or at least the terminology so I can look it up?

Many thanks.

L.

Random Motion
I enjoy the tutorial at

http://www.kirupa.com/developer/mx/random_motionMX.htm

it's very cool. I was messing around with the code, but i can't seem to limit the perimeter that the images are moving. The images are moving beyond the set

// specify the width and height of the movie

width = 300;
height = 200;


is there a code that I can allow for the images not to pass the desired width and height?

If you do not know what i'm talking about, u can click on the link above. Notice how the cones go beyond the width and height that is set.

Thanks for reading and any help is appreciated.

More Random Motion
Ok, so I've been playing with the random motion code from the vibrate tutorial and I have a question.

I like the effect I'm getting but I'm wondering if it's possible to write some code to animate the movement between the random jumps the objects make. I'm trying to create random motion with smooth transitions.

HELP - Containing Random Motion
Hi all, if anyone could help me with this I'd greatly appreciate it. I'm experimenting with random brownian motion and it works great. Code below:

goto=Math.random()*Math.PI*2
x=x+r*Math.cos(goto);
y=y+r*Math.sin(goto);
this.lineTo(x,y);

so what this gives me is a great random little scribbler that I love. What I can't get it to do is to follow an "approximate path" while moving randomly. I.e. moving randomly within a confined space. I don't want to use the traditional bouding box idea b/c the shape I'd like to confine it to is more complex. What I need is more of a path solution, or a bounding box that is a complex shape. Any ideas anyone?

Best regards,
zf.

Random Motion
I followed the random motion tut but itīs not working.


www.kirupa.com/developer/actionscript/random_movement.htm

Where should I put that code? in a frame or in the Mc or both?

thanks

Random Motion --better
I have studied this tutorial
http://www.kirupa.com/developer/mx/random_motionMX.htm

but i wonder is there anyway to make the motion more smoother? Not so "hard" when the mc change direction?

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.


PHP Code:



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

Random Motion
I just went through the tutorial on random motion and wanted to take it a step further.

I would like to have the items stop on mouseover and load another movie. Basically, this is the bio page for a film company and the pictures of the two people are going to float around in random motion and when you mouse over one or the other, the pictures stop and go to the side and the bios load.

Thanks,

j

Random Motion
Hey All,

http://www.kirupa.com/developer/acti...dom_motion.htm

I was Wondering if there is any code that can flip the image Horizontally when movement travels to the right and of course flip it back when it travels left.

Thanks

vxd

AS3 Random Motion
Help! My balls aren't moving...
"mover" function worked in AS2, but not translating to AS3.


Code:
for (var i:Number = 0; i < 10; i++) {
var ball:Ball = new Ball();
ball.x = Math.random()* stage.stageWidth;
ball.y = Math.random()* stage.stageHeight;
ball.dx = Math.round(Math.random()* stage.stageWidth);
ball.dy = Math.round(Math.random()* stage.stageHeight);
ball.alpha = Math.random() * .9 + .5;
ball.scaleX = ball.scaleY = Math.random() * 4.5 + .8;

addChild(ball);
ball.addEventListener(Event.ENTER_FRAME, mover);
}

function mover(e:Event):void {
this.x += (this.dx-this.x)/.2;
this.y += (this.dy-this.y)/.3;
if(Math.round(this.x) == this.dx) {
this.dx = Math.round(Math.random()* stage.stageWidth);
this.dy = Math.round(Math.random()* stage.stageHeight);
}
}
Noob missing something simple?

Random Motion
I enjoy the tutorial at

http://www.kirupa.com/developer/mx/random_motionMX.htm

it's very cool. I was messing around with the code, but i can't seem to limit the perimeter that the images are moving. The images are moving beyond the set

// specify the width and height of the movie

width = 300;
height = 200;


is there a code that I can allow for the images not to pass the desired width and height?

If you do not know what i'm talking about, u can click on the link above. Notice how the cones go beyond the width and height that is set.

Thanks for reading and any help is appreciated.

More Random Motion
Ok, so I've been playing with the random motion code from the vibrate tutorial and I have a question.

I like the effect I'm getting but I'm wondering if it's possible to write some code to animate the movement between the random jumps the objects make. I'm trying to create random motion with smooth transitions.

HELP - Containing Random Motion
Hi all, if anyone could help me with this I'd greatly appreciate it. I'm experimenting with random brownian motion and it works great. Code below:

goto=Math.random()*Math.PI*2
x=x+r*Math.cos(goto);
y=y+r*Math.sin(goto);
this.lineTo(x,y);

so what this gives me is a great random little scribbler that I love. What I can't get it to do is to follow an "approximate path" while moving randomly. I.e. moving randomly within a confined space. I don't want to use the traditional bouding box idea b/c the shape I'd like to confine it to is more complex. What I need is more of a path solution, or a bounding box that is a complex shape. Any ideas anyone?

Best regards,
zf.

Random Motion
I followed the random motion tut but itīs not working.


www.kirupa.com/developer/actionscript/random_movement.htm

Where should I put that code? in a frame or in the Mc or both?

thanks

Random Motion --better
I have studied this tutorial
http://www.kirupa.com/developer/mx/random_motionMX.htm

but i wonder is there anyway to make the motion more smoother? Not so "hard" when the mc change direction?

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.


PHP Code:



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

Random Motion
I'm trying to make add this little movie clip to my page but I can't seem to get it to work properly. What I'm trying to do is this. I have a bunch of short lines and i want them to move up and down smoothly and continously. I looked at the random motion tut on the site but it didn't look like what I was after.

Can some one help?

Thanks

PS. you can view the site at www.jcgsolutions.ca so you can have a look at what I'm talking about. The movie clip is in the upper right corner.

jayjay

Random Motion
I admit that I'm not too smart. I've just begun using FMX and I am revamping my website using a full-flash site (flashnetized, or what have you). I really want to use the Random Movement AS that is here, but when I add it to my existing movie - nothing moves. What am I doing wrong? Please help me, I'm dumb.

Random Motion
I just went through the tutorial on random motion and wanted to take it a step further.

I would like to have the items stop on mouseover and load another movie. Basically, this is the bio page for a film company and the pictures of the two people are going to float around in random motion and when you mouse over one or the other, the pictures stop and go to the side and the bios load.

Thanks,

j

Using Random Motion
hello ive created an external .as file and this is my code:

Code:

import mx.transitions.Tween;
import mx.transitions.easing.*;

bigButton.onPress = function(){
   var it:Tween = new Tween(bigButton,"_y",Strong.easeOut,bigButton._y,randomNum,1,true);
}

var randomNum = Math.random()*300;

and here is the code from my flash file:
Code:

#include "externalas.as"

so when I press the bigButton movieclip it randomly goes to a location determined by the random(); function.

BUT when I press the bigButton again it does nothing!

can anyone tell my why this is and help me so that if i click on it once it will go to a random place and then if i press i press it again to another random place.

please help

Random Programatic Motion
I want to create a sort of type engine, if you will. Here's what I'm doing. I am working with animating sentences of text and I don't want to tween letter by letter. It will be too tedious to tween all the text that I have. So I would like to create some action script that can animate the sentences over the timeline.

I thought I could use an array to hold my text and then maybe use the new createTextField to build the sentences on screen. I will need to create a text field for each letter so it can move on its own. Once I get the letters in their individual textfields I need them to move around the stage and then come together to form the sentence.

Anyone have any thoughts?
Thanks

Erik

Random Motion With Reflection
Hi, I am trying to have an object float around in a random motion, with a reflection.

I found the randome movement code somewhere, and tried making it work with the reflection. It works on the x, but not y ... it makes the reflection keep rising and rising untill it goes behind the object.

Please tell me what im doing wrong, TIA

onClipEvent (load) {
width = 5
height = 5
accelFactor = Math.ceil(Math.random()*4) + 2;
newX = Math.round(Math.random()*width);
newY = Math.round(Math.random()*height);
}

onClipEvent (enterFrame) {
currentlocx = this._x;
currentlocy = this._y;
differencex = newX-currentlocx;
differencey = newY-currentlocy;
accelx = differencex/accelFactor;
accely = differencey/accelFactor;
this._x = this._x+accelx;
this._y = this._y+accely;
_parent.reflect._x = _parent.reflect._x+accelx;
_parent.reflect._y = _parent.reflect._y-accely;
if (Math.round(this._y) == Math.round(newY) && Math.round(this._x) == Math.round(newX)) {
newX = Math.round(Math.random()*width);
newY = Math.round(Math.random()*height);
accelFactor = Math.ceil(Math.random()*4) + 2;
}
}

Circular Random Motion
Hello, I'm currently working on building a website
using flash. I wanted to make it more
interactive, so I decided to use actionscripting.
When I was surfing a net for ideas, I found one site
that I think will give me a good idea of what to do.
http://members.shaw.ca/kanda1272/hima.swf
if anyone knows the way to make this kind of random circular motions
of the ball in the loading scene, please tell me

Random Motion Problem
I have this codeon a movie clip which I would like to move on its own.


onClipEvent(load) {
this._x = Math.random()*800;
this._y = Math.random()*50;
speed = Math.random()*2-2;
drift = Math.random()*4-2;
scale = Math.random()*10*5;
}

onClipEvent(enterFrame) {
if (this.getProperty._y < 600) this._y - speed;
if (this.getProperty._y > 0) this._y + speed;
this._x += drift;
this._xscale = scale;
this._yscale = scale;
}

It moves but is reading the _y value for the if statements only in the begining. I am tring to have the clip move back and forth on the screen.

How do I make the loop that always checks for the _y value?

Gravity And Random Motion
Hi,

I was looking to create an effect similar to a bug being drawn to a bug zapper. I read one of jbum's excellent posts about creating gravity towards a planet and this seemed perfect. However, I also would like to have random motion on the bug. The random bug motion seems to cause a problem with the code I am using to create gravity towards the bug zapper.......

code:
bz = _root.bugZapper;
shake = 10;
s = 3;
_root.onEnterFrame = function() {
//position of zapper
posX = _root.bz._x;
posY = _root.bz._y;
// vector to bug
dx = posX-bug._x;
dy = posY-bug._y;
// distance to zapper
dist = Math.sqrt(dx*dx+dy*dy);
// Maximum distance from zapper
MaxDistance = Stage.width;
// Maximum Pull - (pull of zapper)
MaxPull = .2;
// pull - gets more powerful as you get closer to zapper
pull = (MaxDistance-dist)*MaxPull/MaxDistance;
var pullx = dx*pull/dist;
var pully = dy*pull/dist;
bug.vx += pullx;
bug.vy += pully;
bug._x += bug.vx;
bug._y += bug.vy;
};

// bug motion
_root.bug.onEnterFrame = function() {
// current bug position
my_x = this._x;
my_y = this._y;
// bug rotation
myRotation = this._rotation;
// random to add to rotation
myRandom = random(2);
if (myRandom == 0) {
myRandom = -1;
}
// add random to shake
myShake = shake*myRandom;
// add random shake to rotation
myRotation = myRotation+myShake;
// degree conversion
myRotation_rad = (myRotation*3.14159265358979)/180;
// new x position
new_x = my_x+(s*Math.cos(myRotation_rad));
new_y = my_y+(s*Math.sin(myRotation_rad));
// new rotation
this._rotation = myRotation;
// boundary for bug movement
if ((new_x>7.5) && (new_x<400)) {
this._x = new_x;
} else {
myRotation = 180-myRotation;
}
if ((new_y>7.5) && (new_y<400)) {
this._y = new_y;
} else {
myRotation = -myRotation;
}
// current rotation
this._rotation = myRotation;
};


Any suggestions as to how to make the gravitation towards the bug zapper more realistic with the random motion of the bug?

NTD

Efficiency. Random Motion.
I made bug randomly run around inside a box. it works, but whenever i look at someone elses code it is all complicated with weird functions i have never heard of. i tend to just code up everything as simple as possible, although it may be ineficient.

here is the code for the motion of the bug, any pointers on how to clean it up or make it better? I have included swf also. I would like to make this into a tutorial and post it.


Quote:




//if out of box, stop play
if (bug._x>=Xmax || bug._x<=Xmin || bug._y>=Ymax || bug._y<=Ymin) {
movStop = 1;
errText.text = "Put bug back in box!!!";
gotoAndStop(3);
} else {
//errText._alpha = 0;
movStop = 0;
errText.text = "";
dist = Math.random()*maxJump;
theta1 = Math.random()*rangeAngle-bug._rotation-rangeAngle/2;
theta = theta1*Math.PI/180;
Xnew = bug._x+Math.cos(theta)*dist;
Ynew = bug._y-Math.sin(theta)*dist;
bug._rotation = -theta1;
//if next moves puts out of box, reflect motion
if (Xnew>=Xmax || Xnew<=Xmin && movStop == 0) {
bug._rotation = -(bug._rotation+180);
theta1 = Math.random()*60-bug._rotation-30;
theta = theta1*Math.PI/180;
Xnew = bug._x+Math.cos(theta)*dist;
}
if (Ynew>=Ymax || Ynew<=Ymin && movStop == 0) {
bug._rotation = -bug._rotation;
theta1 = Math.random()*60-bug._rotation-30;
theta = theta1*Math.PI/180;
Ynew = bug._y-Math.sin(theta)*dist;
}
//set new coords
bug._x = Xnew;
bug._y = Ynew;
if (varDraw == 1) {
pen.lineTo(bug._x, bug._y);
}
gotoAndPlay(2);
}

Random Circular Motion
Does anybody have any random code I can slap on a movieclip that will look like a bird (seagull) moving in the distance? I tried tweening it it but it just looks too repititive and boring.

I'm looking for something that moves kinda in a circular motion.

[F8] Random Motion With Rotation... PLEASE
Ok, I've alredy posted a thread about this, but now it is really old and no-one is going to reply to it, so i'm going to ask again, PLEASE can someone tell me a good random motion script WITH rotation? I've serched everywhere and I cant find anything...

Random Motion Paths In As3
hello, im wanting to make a random swimming pattern for the fish in a fish tank. the concept is this:
no 2 fish would swim in the same pattern
you setup boundries for the edge of the fish tank
and last they rotate around when hitting the boundries

can someone give me an idea of how this might be accomplished?

Random Characters In Motion. A Little Help?
I'm about to attempt something that imagine there are simple ways of handling. I want to fill a silhouette of a person with text. Just random (or predetermined if that's easier) letters falling and piling up inside of the silhouette until they reach the top. As I envision it the final result will look like the letters pile up to form a person. Therefore if the letters are blue the person's silhouette will be blue and so on.

I can go through, idividually inputting and animating all the letters but that would be highly time consuming and, I'm guessing, not the best way to go about things. So I was wondering if anyone else had any ideas, possibly involving actionscript to generate the letters and control their motion? I'm guessing that if I can handle that via action script then the only actual tinkering involved will just be in masking off the area the text falls into.

So thanks in advance to anyone who can help. Is there anyone?

-Snape

Stop Random Motion?
HI, I have an MC that uses this for random motion. the following AS is in the first frame of the MC
start code:

this.enterframe
acceleration = 220;
newpos = function () { ranx = Math.round((Math.random()*54));rany = Math.round((Math.random()*54));};
newpos();
this.onEnterFrame = function() {
this._x += ((ranx-this._x)/acceleration);
this._y += ((rany-this._y)/acceleration);
if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
newpos();
}
};

Natural Random Motion
I've seen lot's of threads and tutorials regarding random motion, and some of the AS techniques work quite well. However, all these methods result in roughly the same thing - any number of objects moving in a random direction until either stopping or running into the edge of the canvas, then choosing a new direction and starting again.

Is there a method of random motion using Actionscript that would allow for a more natural, fluid movement? More like how an insect might move; in a curvy path rather than a straight line.

Any ideas or links to examples would be greatly appreciated!

-Seth

AS 3 Random Motion Within Bounds
Ok,

I have a script that produces random motion along the y axis, however, I want that motion to occur within the movie clip that is centered on the stage, or I should say within the bounds of that movie clip.
The movie clip has a height of 335 px

Here is the code:


Code:
var xTween:Tween;
var yTween:Tween;
startTween();

function startTween(e:TweenEvent = null):void {
yTween = new Tween(box, "y", Elastic.easeInOut, box.y, Math.random()*300, 2, true);
yTween.addEventListener(TweenEvent.MOTION_FINISH,startTween);


}
any help is appreciated

Thank you
-D

Many Symbols, All Need Random Motion.
Hi all. I'm 4 hours 18 mins into my learning of AS3, so bear with me.

I have a lot of movie clips, each one is a blade of grass. I want to give them all a random rotation value and am using the Tween library to do this for each blade:

import caurina.transitions.*;

function grassMover()
{
Tweener.addTween(grass, {rotation:Math.random()*45,
time:5, onComplete:grassMover,
transition:"easeOutElastic"});
}

grassMover();

---

Now, how can I import a list of movie clips into this code, or to put it another way, how do I make this effect about 200 movie clips, so they all have random rotation? Imagine 200-odd blades of grass, they all need to rotate randomly within a given range.

Hope that makes sense.

A.

Random Motion Question
Hi everyone,

I followed this tutorial http://www.kirupa.com/developer/actionscript/random.asp and everything works fine. But I need the Random Motion to start at a particular frame so how can I achieve that?

I am a complete beginner in Flash and ActionScript so sorry if that seems like a very stupid question to you.

Random Motion Background
I am a very basic flash mx programmer and I am making an animated header for my website. I have started with Kirupa's tutorial on random motion with objects. Now what I want to happen is....

1. I want it to load the random motion.
2. I want it to then have layer above that fades in to a color.
3. I want the random motion to continue in the background while stuff above the transparent color is going. I.E. site name, description, etc.

I have tried create new layers and working on it but the random motion always repeats on one frame. I don't know how you can let the random motion continuely being sent back to frame 1 and have the stuff above it work. Any ideas?

Random Motion Not Working
I did the random motion tutorial (mx version) on kirupa, and it isn't working the way I expected. I made a new movie clip that consists of a simple white dot, and put did everything else. When I start the movie the white dots jump around rather than moving smoothly. What did I do wrong

Random Motion In Background?
Ive followed the random motion tutorial, http://www.kirupa.com/developer/acti...dom_motion.htm but it puts it on top of everything i already have. I need it as a background, how can i knock it down a couple of levels? Thanks in advance.

Random Motion Tutorial
Hey guys

I'm having a little trouble with the Random Motion tutorial

http://www.kirupa.com/developer/actionscript/random.htm


The problem is not that I can't get it to work, but that I can't get it to work under MX (flash 6 export), which I would prefer because I would like to incorporate it into an existing project I am working on, which has MX only code...

Is there a way this tutorial can be modified to work with MX?

thanx for the help

FW

[mx] - Random Motion --> AS 2.0 Class
Greetings All,
I've been trying to convert this tutorial
into an AS 2.0 class. Then it occurred to me -- I have no idea how to do it. Can anyone help me out with this? I'm certain it's a quick project for someone who actually knows what they're doing, but apparently that ain't me.
Any help would be greatly appreciated.

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(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

Copyright Đ 2005-08 www.BigResource.com, All rights reserved