Random Object Spawn

Subscribe to Random Object Spawn 10 posts, 4 voices

 
avatar for eTrioMedia eTrioMedia 6 posts

Well, I’m new to action script (I know the very basic stuff) and I’m planning on making a very basic game to start with.

For my game, I need to know how to make one object (a movie clip symbol) Spawn off stage (above it at a random place), then fall down at a random speed. Also, how do I control the limit of the number for the Math.Random() function?

Thanks.

 
avatar for SalsaJoe13 SalsaJoe13 420 posts

to spawn the object search for tutorials on attachMovie(), for theMath.random(), it puts out a random number x, when 0>x>1, so if you want the number to be a random number 0 to 100, make the code Math.random()*100.

 
avatar for eTrioMedia eTrioMedia 6 posts

Thank you very much, Is there a way to control the random between like 5 – 15?

 
avatar for SumYungGai SumYungGai 24 posts

something like (Math.random()*-10)+15

thats how to do it is on excel at least…so I would think same principles apply

 
avatar for eTrioMedia eTrioMedia 6 posts

I think that works :P It gave me 12.34 and some odd decimals the first time. Thanks.

 
avatar for SumYungGai SumYungGai 24 posts

np, maybe do a rounding function? Idk how but =P if you wanna try…I wont stop you

Also ill explain the code, A number spawn between 0 and 1, so -10 multiplied by 0 is 0 and by 1 is -10

If you add 15 to -10 you get 5, adding 15 to 0 gets you 15, so your minimum is 5 and maximum is 15

 
avatar for eTrioMedia eTrioMedia 6 posts

:P Thanks for explaining. Rounding is going good… Just getting this Random Object spawning to work the hard thing.

 
avatar for BigCheese BigCheese 367 posts

To round you can use Math.round(x); (I think) Or you can chop off the decimal with Math.floor(x);

 
avatar for eTrioMedia eTrioMedia 6 posts

Thanks Cheese.

Anyone know a Math.random() Equation to get between 100 – 450

I’ve trying to figure it out for 20 minutes :P

NVM :D

 
avatar for SumYungGai SumYungGai 24 posts

Anytime you want a between use this equation …........ random*(highest-lowest)+lowest