# [solved] problem with degrees

Get help using Construct 2

### » Tue Feb 05, 2013 3:08 pm

Hello

I want to spawn an object in a random location around another object. I have this working however now i want to cut out a piece of the pie. The object should not spawn between 220 and 230 degrees however i can't get this to work. I have some idea's of how it might work but i just don't see how i would implant this atm.

Here's an example of the 360 spawn
https://dl.dropbox.com/u/139739932/test/randomspawn.capxSemo2013-02-05 18:49:31
B
12
S
2
G
3
Posts: 59
Reputation: 2,628

### » Tue Feb 05, 2013 3:51 pm

Hmm, could you not have a sprite covering the area you do not want them to appear in? Then have them only spawn if not over area?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 928
Reputation: 9,354

### » Tue Feb 05, 2013 4:14 pm

B
140
S
58
G
35
Posts: 2,547
Reputation: 30,650

### » Tue Feb 05, 2013 4:31 pm

Global variable:
random = 0

Instance variable:
Sprite2 (angleBetween = 0)

Event:
Every tick >
Set random to (random+1)
Sprite2 (Set angleBetween to (angle(sun.X,sun.Y,Sprite2.X,Sprite2.Y))

Here control the angle which you don't want object to spawn~

if Sprite2 (angleBetween <= 130) or (angleBetween >= 140)
Sprite2 spawn GreenDot on layer 0 (Image Point 0)

You may ask my angle is between 220 & 230~
But why the angle in the code is (<= 130) or (>= 140)~
That's because the calculation of angle(x1,x2,y1,y2)~
The return answer is between (-180 to 180 degrees)~
Start from opposite direction of the object~
Yup. That's it. Hope it help. (^_^)
B
13
S
5
G
3
Posts: 63
Reputation: 3,989

### » Tue Feb 05, 2013 5:38 pm

Thanks for all the replies.

[QUOTE=shinkan] -snip- image[/QUOTE]

This did not work for me and looking at what AkiraWong wrote i think i know why. "Is between values" does not let me set a value as >=

[QUOTE=AkiraWong] Global variable:
random = 0

Instance variable:
Sprite2 (angleBetween = 0)

Event:
Every tick >
Set random to (random+1)
Sprite2 (Set angleBetween to (angle(sun.X,sun.Y,Sprite2.X,Sprite2.Y))

Here control the angle which you don't want object to spawn~

if Sprite2 (angleBetween <= 130) or (angleBetween >= 140)
Sprite2 spawn GreenDot on layer 0 (Image Point 0)

You may ask my angle is between 220 & 230~
But why the angle in the code is (<= 130) or (>= 140)~
That's because the calculation of angle(x1,x2,y1,y2)~
The return answer is between (-180 to 180 degrees)~
Start from opposite direction of the object~
Yup. That's it. Hope it help. (^_^)[/QUOTE]

I understand what you wrote and thanks for explaining how the degrees work. However like i said above it wont let met change it to >=. I also don't get why you put a +1 to random.

While AnD4D solution seems to work it still bothers me that i can't get it to work with your or shinkan solutions. Sorry to ask this but maybe a capx file would help me understand.

Semo2013-02-05 17:40:03
B
12
S
2
G
3
Posts: 59
Reputation: 2,628

### » Tue Feb 05, 2013 5:56 pm

@Semo
Actually you can use random(360). It's OK, no problem~
The (random+1) is just my sudden idea~
"Is between values" is using >= & <=~
Just type your value (variable name) with upper and lower bound~
And press OK~
B
13
S
5
G
3
Posts: 63
Reputation: 3,989

### » Tue Feb 05, 2013 6:47 pm

Ah i see my mistake. I used system "is between values" instead of sprite "is is between" Silly me.

One thing though. You used an instance variable for angleBetween which does not work because "is between values" does not take 0 with a an instance. Changed it to a global variable and that did the trick!

Thanks a lot for explaining it.
B
12
S
2
G
3
Posts: 59
Reputation: 2,628