Random Movement And Collision
hi
could someone help with this as i haven't got a clue where to start. i want two objects, lets say the letter a(as a libary oblect) and the letter b(as a libary oblect) to randomly appear on the screen, say 800x600 and then randomly move. i am then after collision detection that if any a object hits any b object they both dissappear and make a c object.. .
please help as i really would like to see this work.. .
many thanks
FlashKit > Flash Help > Flash ActionScript
Posted on: 02-28-2003, 12:26 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Random Movement And Collision
hi
could someone help with this as i haven't got a clue where to start. i want two objects, lets say the letter a(as a libary oblect) and the letter b(as a libary oblect) to randomly appear on the screen, say 800x600 and then randomly move. i am then after collision detection that if any a object hits any b object they both dissappear and make a c object.. .
please help as i really would like to see this work.. .
many thanks
Random Movement And Collision
i want to create a numbers of mc moving in a random motion, when the mc hit each other it will bounce back or move away from each other. need help on script.
thanks!
Random Movement & Collision
Hello,
I am trying to make a movie where a movie clip (e.g. a circle) moves around the screen randomly, changing direction when it hits the edge of the screen (or any other defined boundary), using actionscript for the animation and collision detection.
I am struggling to find any resources to get me started with this, so any help would be great.
Thanks for your time,
All the best,
Tim
Random Movement And Collision
Hello,
I am trying to build a movie where a shape (e.g. a circle) moves around the screen at random, changing direction when it collides with edge of the screen (or any set boundary).
I'm strugglling to find a starting point for this so any tips or advice would be great,
Thanks for your time,
All the best,
Tim
Help With Random Movement And Collision Pls.
HI.
I have 2 cars i want to move randomly on my stage. Furthermore i would like them not to "crash" into eachother. This is the code i have so far on my car movieClips
ActionScript Code:
onClipEvent (load) {
speed = 0;
action = random(3)+1;
maxX = 550//Stage.width;
maxY = 400//Stage.height;
}
onClipEvent (enterFrame) {
if (this._x>maxX) {
this._x = 0-(this._width/2);
}
if (this._y>maxY) {
this._y = 0-(this._width/2);
}
if (this._x<-100) {
this._x = maxX+(this._width/2);
}
if (this._y<-100) {
this._y = maxY+(this._width/2);
}
if (lastActionTime == undefined or getTimer()-lastActionTime>400) {
lastActionTime = getTimer();
action = random(5)+1;
}
if (action == 1) {
speed += 2;
} else {
if (action == 2) {
speed -= 1;
} else {
speed *= .9;
}
}
if (Math.abs(speed)>25) {
speed *= .6;
}
if (action == 3) {
// left
_rotation -= speed;
}
if (action == 4) {
// right
_rotation += speed;
}
speed *= .9;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.5;
}
}
It work OK but not as good as i hope for. My main problem is with the car driving outside my stage and the second is that i cant get a collision detection to work
Can someone PLS. help me...
Random Movement + Collision Detection
I'm trying to make a map of my office with people (circles) moving around randomly and need a code that will tell them to move around and not run into the walls. I understand the collision detection .fla file (hittest_example) and the random movement file (randommx) but don't know how to put the two together. I also need the people to be somewhat contained within their offices and walking down the hallways... here's my .fla file if someone can help!
Random Movement + Collision Detection
I'm trying to make a map of my office with people (circles) moving around randomly and need a code that will tell them to move around and not run into the walls. I understand the collision detection .fla file (hittest_example) and the random movement file (randommx) but don't know how to put the two together. I also need the people to be somewhat contained within their offices and walking down the hallways... here's my .fla file if someone can help!
Movement/collision Bug
i extracted a part of my work file coding into this fla, hope that someone can help me solve this buggy problem.
sometime my character just stucked at a position after moving for a while, or it could just pass through the obstacles. I did a trace and realised that it couldnt set back my _global.check to false when keyboard button is already released.
I've tried using :
if (Key.getCode == Key.Up) {
_global.check = 0;
}
The bug comes out once in a while, anyone have an idea how to solve it ?
*Note : All my movements are coded inside the animations MC, as it's required to make the movement of character more natural~
my fla file
Movement With Collision
Hope you can help me
what I am trying to do is move an arrow using a button to a _y cooridnate so when it hits a black dot it stops.
here is my code so far
frame 1
Code:
easeSpeed = 5;
this.planetdisbox.onEnterFrame = function() {
this._y += (yMove-this._y)/easeSpeed;
};
_root.ee.merTxt.onRelease = function() {
yMove = _root.ee.planet1.mer._y;
};
and placed this code onto button
Code:
on(press){
planetdisbox.yMove = _root.ee.planet1.mer._y;
}
see attached gif to see what i want
that once again dev shed
[MX] Mouse Movement Collision
You know those games where you press up and down and your guy stops going up if he hits the top wall and the same for the bottom wall? That's what I'm trying to do but with the mouse. Right now I'm trying to make just the top wall. I came up with this and once the guy hits the wall he stops moving.
PHP Code:
move=true;
onEnterFrame = function() {
if (move==true) {
guy._x=_xmouse;
guy._y=_ymouse;
}
if (guy.hitTest(wall)) {
move=false;
}
}
I don't know how to do it.
Collision Detection / Keyboard Movement
u guys have help'd me before and i hope u can do it again
Im trying to combine moving a MC with the keyboard and using collision detection on the same MC. Im not that good at action scripting but i found Maze.fla in the macromediasamples folder and changed it a bit (i needed the wall detection) ... what i need is :
moving the MC with the keyboard and when that MC touches a different MC it will start new actions ... like change to another scene, an explosion or stuff like that
The keyboard movement and the wall detection is working fine but i cant work out how to combine it with collision detection ... ive tried several different tutorials from Kiruna, Flashkit and other places ... but none works the way i need it to work
hope u understand my problem AND can help me
Collision Detection & Group Movement
I'd like to be able to do what's illustated in the attached picture...
* Have 8 circles on the screen
* Click in top right corner of the rectangle
* All 8 circles move toward the clicked point, but they do not overlap each other as they move and they also respect the boundary walls and avoid them.
* Finally all 8 circles come to rest in upper corner
In essence, I'd like to figure out how the circles should handle the bottleneck and then have them come to rest in the upper right corner. Even if they never stopped trying to get to the point clicked, that would be fine too for now. It would be cool if I could click anywhere on the screen and see them move as a group back and forth thru the bottle neck in different corners/sides/resting in the bottle neck.
Thanks for any help,
Supra
Collision Detection + Keyboard Movement
im tryin to make a mc move around ind a building using the keyboard and when the mc hits the wall it stops. I also want to make "hot spots" to trigger other kind of actions.
I dont know that much about action scripting, but i found maze.fla in the macromedia folder and managed to figure out how to use that for the keyboard movement and wall detection i needed for my idea.
What i cant figure out is how to make the "hot spots".
What i need is when you move one mc (name : otherMC) over another mc (hotspot) things will happen, like an explosion, goto another frame/scene/label.
I tried every collision detection tutorial i could find, but i cant get it to work ...
the code im using is this :
onClipEvent (enterFrame) {
if (this.hitTest(_root.otherMC)) {
gotoAndPlay(2);
}
if (_root.started && _root._currentframe == 1) {
with (_root.otherMC) {
if (Key.isDown(Key.DOWN)) {
_y += 1;
}
if (Key.isDown(Key.UP)) {
_y -= 1;
}
if (Key.isDown(Key.LEFT)) {
_x -= 1;
}
if (Key.isDown(Key.RIGHT)) {
_x += 1;
}
if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= 1;
}
if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += 1;
}
if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= 1;
}
if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += 1;
}
}
}
}
i hope u guys understand my problem and can help me
Collision Detection + Keyboard Movement
im tryin to make a mc move around ind a building using the keyboard and when the mc hits the wall it stops. I also want to make "hot spots" to trigger other kind of actions.
I dont know that much about action scripting, but i found maze.fla in the macromedia folder and managed to figure out how to use that for the keyboard movement and wall detection i needed for my idea.
What i cant figure out is how to make the "hot spots".
What i need is when you move one mc (name : otherMC) over another mc (hotspot) things will happen, like an explosion, goto another frame/scene/label.
I tried every collision detection tutorial i could find, but i cant get it to work ...
the code im using is this :
onClipEvent (enterFrame) {
if (this.hitTest(_root.otherMC)) {
gotoAndPlay(2);
}
if (_root.started && _root._currentframe == 1) {
with (_root.otherMC) {
if (Key.isDown(Key.DOWN)) {
_y += 1;
}
if (Key.isDown(Key.UP)) {
_y -= 1;
}
if (Key.isDown(Key.LEFT)) {
_x -= 1;
}
if (Key.isDown(Key.RIGHT)) {
_x += 1;
}
if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= 1;
}
if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += 1;
}
if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= 1;
}
if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += 1;
}
}
}
}
i hope u guys understand my problem and can help me
Seeking Randon Movement And Collision Detection Tut.
Hi,
I wish to create a MC that will duplicate itself x amount of times. Then, I want those MC's to bounce and float around a confined area, detecting collision of each other and the frame its within.
Does anyone know of a good, straight forward tutorial for me to follow. I've searched and come up with hundreds, so I'd appreciate help in narrowing it down.
Cheers. YP
Movement Started With Key Press And Not Stopped Until Collision Detected
I want to create movement in a movieclip when an arrow key is pressed. I want the movieclip to start moving and not stop until a hitTest recognizes a collision with another object and then tells it to stop. I want the key to only have to be pressed once to start movement and not have to stayed pressed down. How would I do this?
Movement Started With Key Press And Not Stopped Until Collision Detected
I want to create movement in a movieclip when an arrow key is pressed. I want the movieclip to start moving and not stop until a hitTest recognizes a collision with another object and then tells it to stop. I want the key to only have to be pressed once to start movement and not have to stayed pressed down. How would I do this?
Random Rotation To Equal Random Movement Direstion?
k i finally got it so that my things randomly move around the screen and have walls etc etc.. anyways now i wanna know how to make it so that my randomly moving ship will rotate to face there direction if you want i can post the code i am using for random movement and thanks in advance
Random Motion With Collision Detection
HI i am trying to to the above. I have two items on a stage and i only want them to move with in a certine area and bounce off each other when they meet. I found a good random movement code on this site but now im stuck...here is what i have:
onClipEvent (load) {
//data you may want to change
width = 425;
height = 325;
speed = Math.round(Math.random()*2)+ 2;
//initial positions
x = this._x=Math.random()*width;
y = this._y=Math.random()*height;
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;
}
}
Thanks in advance for your help.
Collision-detection In Combination With Random Motion
Hey,
I have 7 mc´s on the stage, which are tweened randomly from one point to another. (i´m using the caurina-tween class)
But they shouldn´t touch each other.
Here an example: http://www.duprez.de/gallery.html (but the pics shouldn´t overlap!)
And here´s a cutout of my AS-code:
Code:
function li1_mov():void {
Tweener.addTween(li1, {x:Math.random()*600, y:Math.random()*500, rotation:Math.random()*300, alpha:Math.random()+0.3, time:7, onComplete:li1_mov, transition:"easeOutElastic"});
}
li1_mov();
How to do this?
greetz
Random Movement, Random Opacity?
I want to create a mc, where a box(50x200) should duplicate itself, and change width randomly. But width should stay in ranges between 50 - 250 px. The boxes should move from left to right, right to left randomly. Also they should have random opacity and random colors(different variations of blue,and red). When the boxes overlap=the opacity should change accordingly, also color changes as they mix. Is creating something like this, or similiar possible?
If so does anybody have examples.
Thnx
Random Movement AND Random Speed
So I got this from the tut on this site and it's works great.
I can't figure out though how to make the speed random as well as the movent.
I want all my little clips to move at random speeds in adition to direction.
Any clues?
Thanks!
---------------------------------------
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 = 600;
height = 400;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+5;
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>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
--------------------------------
onClipEvent(enterFrame){
move();
}
[F8]random Scaling, But With Random Movement?
i am a bit lost. i make a prototype function that randomly scales a box when i click on the stage. i got the scaling right, but why does it move around when it scales?
here is the swf: scaleEase
here is the code:
ActionScript Code:
MovieClip.prototype.scaleEaseTo = function(ease){ onMouseDown = function () { newWidth = 1 + Math.random() * 250; newHeight = 1 + Math.random() * 250; }; this._xscale += (newWidth - this._xscale) / ease; this._yscale += (newHeight - this._yscale) / ease;};dot.onEnterFrame = function(){ scaleEaseTo(5);};
thanks in advance.
Random Movement AND Random Speed
So I got this from the tut on this site and it's works great.
I can't figure out though how to make the speed random as well as the movent.
I want all my little clips to move at random speeds in adition to direction.
Any clues?
Thanks!
---------------------------------------
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 = 600;
height = 400;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+5;
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>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
--------------------------------
onClipEvent(enterFrame){
move();
}
Random Movement
Can anybody help please?
I want a movie clip to move randomly after a certain length of time, then keep looping over the same amount of time and changing the movie clips position randomly. Is there a script which will wait before executing an action, then keep looping that action until anougher condition tells it to do something else?
I tried
if (Number(getTimer()>=500){
---then do a random move function
{
The problem with this is it doesn't keep executing the script until I tell it to stop.
Thanx in advance
Nick
Random Movement
quite a simple one i'm sure.....
I have a series of objects and i want them to randomly move up and down the stage, no interaction necessary, i just don't want to have to tween 10 or so objects.
Is this possible, and is it also possible to replicate the effect of 'easing in and out'
thanks in advance....
Random Movement
i have 10 vertical bars that i want to randomly move across the screen left to right. i dont know how to accomplish this and am hoping that someone would be kind enough to expalain it to me. thank you.
josh
i_am_brucelee@hotmail.com
Random Movement For Mc
Hi everybody,
I am trying to get a movieClip to randomly move around within
a confined area of my stage. When I try to do this it moves very
irraticly and doesnt stay within any boundries.
this is what I tried:
onClipEvent(enterFrame){
this._x=Math.random()*50;
this._y=Math.random()*50;
}
I want a nice fluid motion that will stay in some defined boundries.
Thanks for the Help
Random Movement
u wud think that this wud be simple ah. simple to do, and even simpler to find. nope ..
does anyone know how i may create randomlly moving elements. ie, i want thesse incy wincy things to float around the stage. no collision detect, no nuffin'
i have looked all over this site .. i have found a couple of movie examples, but one is button triggered, and the other is waaaaaaaaaaaaay to complicated.
help Much appreciated.
thx
b
Random Movement
hej venner
could anybody helpme with a script that makes an object (button) move in an nice smooth random path (infinitly , and in an area slightly exceeding the visible)?
i would be most appreaciative@
thank you in advance
[Edited by sjovefro on 06-04-2002 at 12:23 PM]
Random Movement
I'm making a menu and when I go over the buttons I want them to shake. So i guess this would mean some random movment of some kind. Now I'm not very good at A.S., could someone code this up for me. I need the instance to shake, so in other words move from frame to frame move from one location to an other very quickly in a small amount of space.
Thank You,
Sebastien Couture
Random Movement Of MC
Please can anyone please suggest me how can i have a random movement of an movieclip using actionscript.
Arup
Random Movement
is there code that i can use to make a graphic move randomally within a rectangle on screen?
Random Movement
hey all
having some trouble with a game im making. i need an MC to reappear at a random location inside a box. im using this code
setProperty (_root.object, _y, _root.object._y=random(100-350)
setProperty (_root.object, _x, _root.object._x=random(300-250)
im only a beginner and im probably doin somthing stupid here so it would be much appreciated if someone could point me in the right direction??
cheers
Random Movement AS?
Hey,
Does anyone have any code,tips or tutorials involving random movement of an object? I don't mean random x or y values, but fluid movement. A good example would be like a fish moving around - that sort of thing...
Random Movement
Hi There,
I am using the below code to ease a movie clip to a random target, which it does, but I want it to then ease to another random target, once it reaches the target before, so in effect, it is constantly moving to random targets. Any ideas????
On frame 1:
_y=100;
targety=n;
n=random(100-600);
speed=32;
On Frame 2:
distancey=targety-_y;
amount=distancey/speed;
_y+=amount;
On Frame 3;
gotoAndPlay(2);
Thanks in advance!!!
Barry
Random Movement
Im making a game and I needs o have butterflys moving in a random way, I would be very happy for any help. I want then to curve instead of just a sharp corner.
Thanx in advance,
Random Movement
I am making a flash movie for a screen saver I have a Movieclip I want to move all around the stage on a Random basis. How would I code or script the (motion)Movieclip to move around randomly?
If you know some code or a tutorial I would appreciate the help.
Thanks.
Random Movement?
Hey everybody.
Just wondering:
How to make an as moving a MC randomly around a swf.
Example:
An ant moving around the page randomly..
Thank you for your time
Need Random Movement
anybody know of a good tute for making an object move randomly about the stage area.
Random Movement
I'm sure I’ve seen something like this before an image to move up, down, left, right and diagonally randomly using AS.
I plan to have a box let's say size 100x100 and within that box will be an image about 200x200 in size, so all you can see of the image is 100x100 (sort of masking), then the image to move randomly in all directions and if possible with random speed.
Please can someone point me in the right direction.
Many thanks
Michael
Random Movement
Hi,
I looked at some flash-sites and one site draw my attention.
I'm talking about www.derbauer.de.
In there you see a very nice flash-site.
But what I'm interested in is the background.
You see screens opening and closing, stuff appearing and so on....
At first it doesn't look so hard but the thing is, it looks like is doing that randomly.
And that the part i don't get, how does he do that?
Does anyone here know how to do something like that?
Because I don't and I would really like to know.
So would anyone be so nice and tell me or give me an example of how it is done?
Thx
Random Movement
hi everyone,
i need some action script to work with random movement. basically i need fish to swim randomly over the movie but also if they change direction the instance movies needs to be flipped.
Could anyone help me with this problem
thanks.
Random Movement
Im creating a game in which i need to make a load of objects randomly move. Does anyone know how i can do this? I also need them not to disappear off screen. If anyone could help i'd be very greatful.
Thanks
Random Movement
I would like to create some random movement for a mc i made. my stage size is 790 x 600 but the area i want the movie clip to move is is only 720 x 268. www.izzos.com/beta is where the site is and you will see the roll your own text at the top. I only want it to move within that green background area. I have used some scripts before but all of them make my text scroll around the entire stage area. Any help is appreciated, thanks.
Random Movement
Is it possible to have random movement for a movieclip within a restricted area?
If so , anyone have a clue on how to do it?
Random Movement
I'm making a game in an overhead type of view and want to know how to make a movieclip Randomly move around the map and face the direction that it is moving. I have the movie clip moving but it doesn't face the direction that it faces. Which looks really bad.
Random Movement Etc.
Hi,
I'm trying to make these fireflies: http://listic.dk/324fireflies.swf
I have loaded the thing into a flash decompiler, but I must be doing something wrong, because it doesn't work, my .fla can be found here: http://listic.dk/fireflies.fla
I would very much appreciate if one of you experts maybe could take a look at the scripting and see where I'm doing it wrong :-)
All the best
Andrew
Random Movement...
Im trying to get a movieclip to be placed on the stage (from a button press) and move randomly in one direction at one speed.
Eventually ill write the code for it to stop when it hits the edge but im just looking for the random directional movement right now...
any help would be greatly appreciated
|