Random location but certain distance from object

Get help using Construct 2

Post » Thu Feb 23, 2012 3:24 pm

hi

ive been trying to figure out how to create an object in a random location on the screen but a certain distance away from a central object.

this is what i have for random location. every 3 seconds i create an object at location: x = random(0,800) y = random(0,600)

that works great but i dont want them to appear within a certain area of the screen. this image may help to understand what i mean



the red square is my central object
the blue area represents the no-go zone (distance from object)
the green circles represent the random objects

i need the green circles to appear randomly anywhere on screen but not within a certain distance from the central object ie not inside the blue circle.

is there a formula for this?

thanks
B
8
S
1
Posts: 17
Reputation: 634

Post » Thu Feb 23, 2012 3:56 pm

Try creating the object in the middle of the circle, then using the 'Move at angle' action to move it a distance at random(360) degrees.
Scirra Founder
B
395
S
232
G
88
Posts: 24,367
Reputation: 193,744

Post » Fri Feb 24, 2012 10:31 am

Or, make a invisible object, pin it to the player, and check the conditionals:
> Created object is not overlapping the invisible object > spawn;
Image
B
106
S
23
G
17
Posts: 1,357
Reputation: 22,137

Post » Fri Feb 24, 2012 10:59 am

Ashley's idea is the way to go.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679


Return to How do I....?

Who is online

Users browsing this forum: mihirolover, tarek2 and 8 guests