How do I create objects at random spots inside an object?

Get help using Construct 2

Post » Wed Aug 31, 2016 4:05 am

I'm creating a game that has rooms sort of like a zelda dungeon, and I'd like to make pickups randomly spawn in the room the player is currently in. Each room is surrounded by a plain box called obj_spawnzone:

Image
(visually represented here in stunning HD)

What I'd like to have happen is, every 1-10 seconds, a pickup spawns at a random position inside obj_spawnzone. The first part I've got with an "Every round(random(1,10))" event, but how do I spawn the pickups at a random position inside the object? Keep in mind that I don't want pickups to spawn in rooms the player isn't in.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Wed Aug 31, 2016 4:13 am

If you'll use system--create object instead of 'spawning' the pickups, you can use x/y instead of image point. Which will allow you to put random in the x and y parameters.

System-Create Object Pickup at
X: random(obj_spawnzone.bboxleft, ob_spawnzone.bboxright)
Y: random(obj_spawnzone.bboxtop, ob_spawnzone.bboxbottom)

add an 'player is in room' to make sure it won't do it other rooms.
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Wed Aug 31, 2016 5:24 am

Excellent, that works just fine. Thank you! :)
B
18
S
9
Posts: 103
Reputation: 1,817


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests