Spawn an object in a specific range inside a circular area

0 favourites
  • 3 posts
From the Asset Store
Is a circular loading screen with code ready to use. No Animation.
  • Hello everyone!

    I was looking for some solution about my idea, I want to crate an abject in the blue zone but not in the red one:

    So I have read this very interesting post but didn't get something about the code, so maybe someone can give me some explanation. Or maybe I'm all wrong.

    I used this code to spawn my object:

    x = (cos(random(0,1)) * radius) + position

    y = (sin(random(0,1)) * radius) + position

    So I did presume that the (0,1) is supposed to be the start position and the en position. so for my zone, that's probably (118,256)

    My circle is 256 so the radius is 128. Then my code should look like this:

    x = (cos(random(118,256)) * 128) + position

    y = (sin(random(118,256)) * 128) + position

    Unfortunately, it doesn't seem to be correct. Seems that I didn't get how it work so I would appreciate some explanation!

    Thanks

    Tagged:

  • You could do it like this with some variables.

    Radius=random(128,256)
    Ang=random(360)
    X=posX+radius*cos(ang)
    Y=posY+radius*sin(ang)

    Alternately you can avoid some of the math with the move at angle action.

    Create sprite at (x,y)
    Sprite: move random(128,256) pixels at angle random(360)
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks R0J0hound, I'll finally use your alternative solution as it don't request a lot of math and the result is the same!

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