[solved] problem with degrees

0 favourites
  • 7 posts
From the Asset Store
Avoid obstacles and survive as long as you can!
  • 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

    dl.dropbox.com/u/139739932/test/randomspawn.capx

  • 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?

  • <img src="http://dl.dropbox.com/u/34375299/Construct%202/bugs%20and%20fixes/betwen%20angle%20spawn.JPG" border="0" />

  • Global variable:

    random = 0

    radius = 200

    Instance variable:

    Sprite2 (angleBetween = 0)

    Event:

    Every tick >

    Set random to (random+1)

    Sprite2 (Set position to (sun.X+cos(random)*radius, sun.Y+sin(random)*radius"))

    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~

    For your case:

    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. (^_^)

  • Thanks for all the replies.

    -snip- image

    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 >=

    Global variable:

    random = 0

    radius = 200

    Instance variable:

    Sprite2 (angleBetween = 0)

    Event:

    Every tick >

    Set random to (random+1)

    Sprite2 (Set position to (sun.X+cos(random)*radius, sun.Y+sin(random)*radius"))

    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~

    For your case:

    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. (^_^)

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Semo

    Actually you can use random(360). It's OK, no problem~

    The (random+1) is just my sudden idea~

    So that it update like a map radar instead of random~

    "Is between values" is using >= & <=~

    Just type your value (variable name) with upper and lower bound~

    And press OK~

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)