Jump to content


Photo

Newbie..How to make objects spawn at random points


  • Please log in to reply
7 replies to this topic

#1 gordoa40

gordoa40

    GMC Member

  • New Member
  • 1 posts

Posted 10 September 2010 - 03:55 AM

Ok im a newb at game maker (ps im using mac) and for my first game i'm making one of those games where youre a car driving on a road (aerial view) and you have to dodge the spikes and collect the coins. I need to know how to make objects like coins and spikes, spawn randomly in my map. and they need to spawn differently every time. Thanks in advance and tell me if you need clarification (p.s. all the coins and spikes need to spawn in the very begginning of the game, not like every 10 seconds of something and remember they need to be different every time.....AND there needs to be a fixed number of them, just they all spawn at different random points, haha thx)
  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 10 September 2010 - 06:38 AM

I need to know how to make objects like coins and spikes, spawn randomly in my map.

You could put the :GM012: command in the create-event of the coint.

[edit]
Wrong image, I ment :GM013:

Edited by ragarnak, 11 September 2010 - 02:24 AM.

  • 0

#3 gordoa40

gordoa40

    GMC Member

  • New Member
  • 1 posts

Posted 10 September 2010 - 11:25 PM

I need to know how to make objects like coins and spikes, spawn randomly in my map.

You could put the :GM012: command in the create-event of the coint.

but wouldn't that just make it jump to start? i need all of them to spawn randomly in the map at very beggining. if i'm wrong about the :GM012: then please explain and ellaborate thanks
  • 0

#4 smash ball

smash ball

    Volcanic Light

  • GMC Member
  • 1648 posts
  • Version:GM:Studio

Posted 10 September 2010 - 11:48 PM

Posted Image
You can set that to 25 or something.
Now put an instance create(spike or coin or whatever)
Under the instance create for the object, put in this for x and y:
random(your maximum x value)
random(your maximum y value)

Let's say our max x is 100, max y is 200, it would be set up like so:
random(100)
random(200)

If you want a min x and a min y then:
max(random(100), minimum x)
max(random(200), minimum y)
  • 0

#5 shrekboy1

shrekboy1

    GMC Member

  • New Member
  • 116 posts

Posted 10 September 2010 - 11:57 PM

CONTROL OBJECT (STEP):
var a; //Create Temp variable
a=random(4) //set temp to a random number from 0 to 4
if a=1 //if the temp variable is 1
{
instance_create(random(room_width),-100,obj_spike) //create instance anywhere across the room, and 100 pixels above the visible screen
}

try that.
  • 0

#6 smash ball

smash ball

    Volcanic Light

  • GMC Member
  • 1648 posts
  • Version:GM:Studio

Posted 11 September 2010 - 12:01 AM

...That's pretty much what I just said, just in code form...
  • 0

#7 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 11 September 2010 - 02:23 AM

but wouldn't that just make it jump to start?

Yes, it would.

I copied the wrong image, I ment :GM013: Sorry.
  • 0

#8 Binsk

Binsk

    -Insane Kid-

  • GMC Member
  • 2874 posts
  • Version:GM:Studio

Posted 11 September 2010 - 02:31 AM

There should be an example provided which is close to what you are trying to do. Under Program Files-> Game Maker 8/7/whatever -> Examples

Mark provides some top-down scrolling driving example which has gas cans that spawn randomly and stuff. Check that out and I am sure you could get some ideas from it.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users