Spawn object inside area randomly

Get help using Construct 2

Post » Sat Dec 14, 2013 6:11 am

Hello again everyone, here looking for some knowledge and help with C2.

I am planning to add a feature (yep, planning, because I dont know if I can >_<) to my game where an instance is spawned at a random point inside an specific area.

Per say, look at the image I attached, if the object appears or belongs to the first area it will appear inside that area only but at a random position inside of it. Then possibly, later on that same object but with different properties of course, will spawn in the second are again, in a random position, and so on. Do you know if that can that be done in C2?



Thank you all in advance! Ruvier2013-12-14 06:12:16
B
9
S
2
Posts: 19
Reputation: 850

Post » Sat Dec 14, 2013 7:15 am

You could define the area with the clamp expression.

clamp(spawn.x, minimumx, maximumx)
clamp(spawn.y, minimumy, maximumy)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 14, 2013 12:43 pm

@LittleStain
I was wondering you you could provide a capx. Newbies like me may not know how to do that.
Please
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Sat Dec 14, 2013 7:45 pm

Thanks a lot @LittleStain ! But as @producermark11 says, do you have a capx by any chance to take a look?
B
9
S
2
Posts: 19
Reputation: 850

Post » Sun Dec 15, 2013 9:45 am

Actually for this purpose you wouldn't need the clamp expression.

let's say the desired area is a rectangle starting at x=100 y=100 and ending at x=200 y=250

this code would do just fine:

Every x seconds
- system create object
x: random(100,200)
y: random(100,250)LittleStain2013-12-15 09:46:23
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: Madave96, marc254 and 10 guests