# Creating Objects Randomly In A Donut Shaped Area

3 replies to this topic

### #1 H4><0R

H4><0R

GMC Member

• New Member
• 98 posts

Posted 28 December 2008 - 04:51 AM

I am trying to make an asteroid field that surrounds a solar system. I need to create several objects in a doughnut shaped area. And since I got a C in pre-calculus...I need some help with the math. I figured that I would take the circumference of two circles (one big and one small) and somehow figure out the area inside the two rings... And by somehow I mean someone else on the forum, because I have no idea where to even start on this kind of math problem!

Thanks,
h4x0r

Edited by H4><0R, 28 December 2008 - 05:42 AM.

• 0

### #2 squirrel9999999

squirrel9999999

GMC Member

• GMC Member
• 42 posts
• Version:GM6

Posted 28 December 2008 - 05:09 AM

var dir;
var dis;
dir=random(360)
dis=random(100) //replace with how far you want the objects to be able to go

instance_create(320+lengthdir_x(dis+100/*the +100 is the min distance, i.e. inside circle's radius*/,dir),240+lengthdir_y(dis+100,dir),object)

you can replace the 320/240 with wherever you want the origin of the circles to be.

Edited by squirrel9999999, 28 December 2008 - 05:10 AM.

• 0

### #3 xDanielx

xDanielx

GMC Member

• GMC Member
• 1001 posts
• Version:Unknown

Posted 28 December 2008 - 05:21 AM

A somewhat more general/pluggable version:

```// instance_create_inDisk(x_center, y_center, rad_min, rad_max, object)

var dist, ang;

dist = argument2 + random(argument3 - argument2);
ang = random(360);

return instance_create(argument0 + lengthdir_x(dist, ang), argument1 + lengthdir_y(dist, ang), argument4);```

Edited by xDanielx, 28 December 2008 - 05:23 AM.

• 0

### #4 H4><0R

H4><0R

GMC Member

• New Member
• 98 posts

Posted 28 December 2008 - 05:40 AM

Thanks, both of them work if anyone else looking at this topic wants to know.
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users