GameMaker: Studio
 
Find, play, and make games easily
Discover, rate, and download the best player-created games made in GameMaker: Studio for free. Or try making your own and share with the community. Click here to learn more.
Greed 1 Nov 22, 2012 @ 12:46am
How to make things randomly drop from the sky?
I am trying to get comets to drop randomly in my game but i cant figure out how. i tried the create random instance and making the direction they move down but they never appeared. any help would be appreciated.
Showing 1-4 of 4 comments
< >
Joys Nov 22, 2012 @ 6:49am 
Try using instance_create(x,y,object) (horizontal position, vertical position, object name)
If you use it with a random X of a range up to the room width aka random(room_width) and putting 0 for y (so it's at the top), this will probably succeed.

The full instance create code is: instance_create(random(room_width),0,obj_meteor)
Replace obj_meteor with your meteor object!

Every time you call this code a meteor will be created. So it's up to you now how to call this code and how often!
Greed 1 Nov 22, 2012 @ 11:37pm 
ok. ill try it. thanks.
MattchuDeePorkupineh 9 Nov 23, 2012 @ 10:58am 
I'd add that you want to use irandom(x) and not random(x) or else it'll flash due to being at a fraction of a pixel.
Scorcher24 4 Nov 25, 2012 @ 10:47pm 
Put this into an alarm or step function and modify it to your needs.

var xpos;
var new_obj;

// This is a dice of 20 sides, if you want a higher chance, lower the number
if ( irandom_range( 0, 20 ) == 0 )
{
// Get a random location with a little border in the size of the sprite
xpos = irandom_range( sprite_get_width(sprite_index), room_width - sprite_get_width(sprite_index) );

// Spawn outside the players view, so it comes in smoothly and does not pop up
new_obj = instance_create( xpos, -sprite_get_height(sprite_index), objMyFallingStuff);
with (new_obj){
direction = 270; // direction downwards
speed = 20;
}}
Last edited by Scorcher24; Nov 25, 2012 @ 10:49pm
Showing 1-4 of 4 comments
< >
Per page: 15 30 50