Jump to content


Photo

Random object spawning


  • Please log in to reply
6 replies to this topic

#1 Wertpol

Wertpol

    GMC Member

  • New Member
  • 2 posts

Posted 19 March 2011 - 11:01 AM

Well, first post!
I have a problem: I just started to create a cave game of some sort, and want to make caves spawn in the ground of my 2D game.
But if I said "Jump to random position", the object wont spawn in solid objects, but the caves must spawn in the ground.
So yeah, my question is: how can I make an object jump into the solid ground?
No coding please, as I am way too stupid to use it :P
  • 0

#2 Hazard94

Hazard94

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM8

Posted 19 March 2011 - 12:36 PM

Ive tried and I dont know why jump to random doesnt work...
Use Jump to position:
x=random(room_width)
y=random(room_height)

That works...

If there is ground and for example, rocks, and you want the cave only appear on the ground, then I believe you'll need a bit of code.. You can also do it with Drag and drop, but it's better and easier with codes...

Edited by Hazard94, 19 March 2011 - 12:45 PM.

  • 0

#3 GMClay

GMClay

    GMC Member

  • New Member
  • 82 posts

Posted 19 March 2011 - 12:46 PM

ok well i see how i go putting this into drop and drag

so as i understand you are creating objects in random positions but want them not to be at the same location as a different type of object

try this:

Create or room start event

repeat :GM067: lets say 32 times (may need more or less)
start block :GM063:
jump random :GM013: add in grid size (guessing game is formed in a grid)
check collision (couldnt find pic) using x as x and y as y, choosing solid or all, and checking the 'Not' box
exit :GM065:
end block :GM066:

so what happens is that the object jumps to a random position, then checks to see if this place is taken, and if not stops the repeat

hope that was what you were after, and hope it helps :)

if you have any troubles let me know

EDIT:

just tried it on my computer, and while the checking objects did not overlap the solid, they could overlap each other, so i reccommend using all in collision check

Edited by GMClay, 19 March 2011 - 12:53 PM.

  • 0

#4 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3771 posts
  • Version:GM:Studio

Posted 19 March 2011 - 12:53 PM

No coding? A challenge!
Creation event:
:GM072: Set variable "visible" to "false"
Step event:
:GM060: If an expression "not visible" is true
:GM067: Repeat 64 times
:GM063: Start of block
__ :GM013: Jump to random position (snap.hor: "32", snap.vert: "32")
__ :GM055: If there is collision at relative position (0,0) against Solid objects
__ :GM063: Start of block
____ :GM072: Set variable "visible" to "true"
____ :GM065: Exit this event
__ :GM066: End of block
:GM066: End of block
Edit: Hey! That's just what I said. But I have more icons :lol:

Edited by YellowAfterlife, 19 March 2011 - 12:54 PM.

  • 0

#5 A saurus1

A saurus1

    GMC Member

  • Sandbox Moderators
  • 1609 posts
  • Version:GM8.1

Posted 19 March 2011 - 01:28 PM

BTW, yellow, I believe from past experience that Jump to Random automatically avoids all solid objects.
  • 0

#6 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3771 posts
  • Version:GM:Studio

Posted 19 March 2011 - 01:36 PM

BTW, yellow, I believe from past experience that Jump to Random automatically avoids all solid objects.

Hmm. Indeed. Then that line should be changed to
:GM011: Jump to position (floor(random(room_width)/32)*32, floor(random(room_height)/32)*32)
  • 0

#7 Wertpol

Wertpol

    GMC Member

  • New Member
  • 2 posts

Posted 19 March 2011 - 02:58 PM

Wow, thanks for the fast replies! It works now, thanks :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users