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
KirupaForum > Flash > Flash 8 (and earlier) > Flash MX
Posted on: 02-27-2003, 10:06 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
Kitupa Random - Motion Tutorial Help
Can someone pleas help me with this tutorial ? I place the code in the timeline but I dont know where to place them to make the movie clips work?
* do i have to place them on the time line?
* Do the have to be named a certain Way ?
* Do they have to have some code ?
Ill apreciate any help !
Im a beginer
Help With Random Motion/Color Tutorial
Hello,
I tweaked the Random Motion tutorial and added in a random scale and alpha to make random polka dots moving on the screen. It looked great with the white background, but I need it on black. A low alpha on a pink polka dot with a black background... well, it's not really pink. ;-) I found a tutorial that would cycle through random numbers to generate random hex numbers for color. But I need to randomly cycle through these specific colors: #FFB6C1, #FFCOCB, #FFFOF5, #FF69B4.
Can anyone offer any suggestions.
Here is the code on the "dot" MovieClip:
Code:
onClipEvent (load) {
//data you may want to change
width = 760;
height = 600;
speed = Math.round(Math.random()*2)+1;
scale = (random(100) + 50)
this._alpha = random(100);
this._xscale = scale;
this._yscale = scale;
//initial positions
x = Math.random()*width;
y = Math.random()*height;
this._x = x;
this._y = y;
x_new = Math.random()*width;
y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}
//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new = Math.random()*height;
}
}
Trouble With Random Motion Tutorial
I followed the random motion tutorial at http://www.kirupa.com/developer/acti...dom_motion.htm and it's working *almost* perfectly, except that it gives one almighty jerk shortly after my movieclips started roaming. I used the code as it was given in the tutorial, only changing the size of the width and height to the size of my frame.
I have several movieclips, and didn't use the code given to generate duplicates. Could this be the problem? Also, the mcs are masked.
That's it, can't think of anything else that would be making it jump like that. Only does it once. Have been banging my head off computer all afternoon. Thanks in advance to anyone who can suggest a solution - or suggest an alternate (and foolproof) random motion tutorial!
Cheers.
Kitupa Random - Motion Tutorial Help
Can someone pleas help me with this tutorial ? I place the code in the timeline but I dont know where to place them to make the movie clips work?
* do i have to place them on the time line?
* Do the have to be named a certain Way ?
* Do they have to have some code ?
Ill apreciate any help !
Im a beginer
++ Creating Random Motion - Tutorial ++
Hi guys,
I did the Creating Random Motion Tutorial and it works fine. I just have one problem i would like to solve.
I want the movie clip 'ball' (bal=MC name in the tutorial) to be behind the other layers.
This is the action:
Code:
for(i=0;i<50;i++) {
var t = this.attachMovie("ball","ball"+i,i);
t._x = Math.random()*550;
t._y = Math.random()*400;
t.dx = Math.round(Math.random()*800);
t.dy = Math.round(Math.random()*600);
t._xscale = Math.random()*40+10;
t._yscale = t._xscale;
t.onEnterFrame = mover;
}
function mover () {
this._x += (this.dx-this._x)/50;
this._y += (this.dy-this._y)/10;
if(Math.round(this._x) == this.dx) {
this.dx = Math.round(Math.random()*800);
this.dy = Math.round(Math.random()*600);
}
}
Is it possible?
I tryed with _level and depth but didn't succeed.
thank's for helping
Tufi
[F8] Can't Find Good Random Motion Tutorial ANYWHERE
Please can someone help? I've looked everywhere for a good random motion tutorial, and i've found quite a few! But none of them get the object to face in the direction it is moving. I am currently making a cool game called Pligas. It's going to be a bit like the microlife game, and that's exactly the sort of random motion I want. Please?
Random Motion Tutorial With Multiple Movies
Hi,
The random motion tutorial works just perfectly with one movieclip, but when I try to make a new movie clip and assign the same code to it, it really doesn't duplicate at all. The original movieclip has an instance name of dot so I created a new movieclip with instance name of dottwo.
But for some reasob the following code doesn't duplicate the dottwo at all
i = 0;
while (i<25) {
dot.duplicateMovieClip("dot"+i, i);
dottwo.duplicateMovieClip("dottwo"+i, i);
i++;
}
any suggestions?
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.
Motion Tutorial
how do I get a MC to continue to loop thru?
I have this:
onClipEvent(enterFrame) {
speed = 2;
this._x += speed;
}
I just want the MC to continue back onto the screen
Motion Tween Tutorial For MX 2004
I noticed that in the tutorial, there is no mention of having to group your object or converting it to a symbol prior to doing a motion tween on the object. Is this step no longer necessary in MX 2004?
Kirupa's Continual Motion Tutorial
Does anyone have an idea why this will not work for me? I have followed that tutorial exactly. The only thing that I am doing different is using a gif, instead of a flash drawn circle. It scrolls on the screen, but it does not respawn. Please help?
Motion Tween Tutorial For MX 2004
I noticed that in the tutorial, there is no mention of having to group your object or converting it to a symbol prior to doing a motion tween on the object. Is this step no longer necessary in MX 2004?
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
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);
}
}
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...
|