random help

9 posts

Flag Post

how would i make it so that a movieclip randomly appers on the screen and stays there???

 
Flag Post

var t:MovieClip;

n = _root.getNextHighestDepth();

t = attachMovie(“foo”,"foo"+n,n);

t._x = Math.random() * Stage.width;

t._y = Math.random() * Stage.height;

where foo is linkage name for movieclip in library

 
Flag Post

Aarhhh thanks :D

(Was looking for that!)

 
Flag Post

also how would i make it so that like in ragdoll avalanch things fall randomly from the cieling

 
Flag Post

Well, dx’s code shows you how to pick a random start position. Just make the ._y value above the stage. Then you need some sort of motion function that changes the _y positions of each movie clip by whatever speed you’ve assigned to it (probably want those to be bounded random numbers as well). There are lots of tuts out there for making things move on screen.

 
Flag Post

use a code like a movement code but have it so it goes down on its own and without a key press. you can also do a gravity simulation

 
Flag Post

how do you make gravity???

 
Flag Post

Gravity is pretty simple. Ok, say you have a ball MovieClip (ball) and you want to give it some gravity. I’m assuming that the ball will have some velocity (vx, vy : velocity on x and y axis) and a gravity constant (gravity). Here’s the code:

var gravity:Number = 0.03;

this.onEnterFrame = function():Void {
  //apply gravity to y velocity (pulls down)
  ball.vy += gravity;

  //move the ball
  ball._x += ball.vx;
  ball._y += ball.vy;
}
 
Flag Post

thanks