Spawn sprites randomly within a circle

  • Hiya

    Any ideas how you'd make enemies randomly spawn within a circular (or any irregular) shape?

    I don't want to hard code spawning locations if possible.

  • Try Construct 3

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

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

    Maybe after a circle is spawned you set the circle to spawn random sprites at locations inside the Area of the circle.

    If the area of your circle is 200 then the radius is 100.

    So maybe something like this:

    Event>>>Circle on screen

    Action>>> Create object on positions (circle.width/2 + random(-100,100),circle.height/2 + random(-100,100)

    I think this will spawn enemies within the radius of the circle and then add or subtract a couple of distances within the circle. The -100 to 100 is the interval I guess, so once the position of half the circle is decided the system will either subtract or add a value between -100 to 100 to the center point of the circle giving your a random spot within the circle.

    You could probably replace the value of 100 with the radius that you want for your circle

    Hiya

    Any ideas how you'd make enemies randomly spawn within a circular (or any irregular) shape?

    I don't want to hard code spawning locations if possible.

  • Well spawning within a irregular shape is different than a circle.

    for circle

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

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

    for an irregular shape

    uses boxes. randomly spawn based on the box. put the boxes in whatever shape you want. # = spawn box, O = no spawn box but open space

    #O#

    ###

    OO#

    That would be an irregular shape if the players can't see the spawn boxes :D

  • Thanks guys

    I was trying to spawn in lots of different shaped windows, hexagonal, circular, Anthony you can think of, without design-time hard coding.

    I don't think there's anything at the moment that allows sprite within sprite "bounding box" constrained random points.

    Once I figure out how to make plugins I might look into making one for this.

  • jayderyu can u make a capx of this

  • touch 0 end - create objects on [square.X + random(-square.width/2, square.width/2), square.Y + random(-square.height/2, square.height/2)];

    it's an approach of a square.

    If I remember my last solution for it, I'll come here and share.

    Edited:

    If your radius is the same circle width/2, use:

    = Touch 0 end

    -> Create objects on [circle.X + cos(random(360) * circle.width/2), circle.Y + sin(random(360) * circle.width/2)];

  • touch 0 end - create objects on [square.X + random(-square.width/2, square.width/2), square.Y + random(-square.height/2, square.height/2)];

    it's an approach of a square.

    If I remember my last solution for it, I'll come here and share.

    Edited:

    If your radius is the same circle width/2, use:

    = Touch 0 end

    -> Create objects on [circle.X + cos(random(360) * circle.width/2), circle.Y + sin(random(360) * circle.width/2)];

    Forgive me for replying to an old post. Just wanted to tell anyone else that might want to know how to solve this problem. This solution worked really great for me. Thanx guys.

  • hi,

    I tried:

    Every 0,1 seconds:

    Create object on (circle.X + cos(random(360) * circle.width/2), circle.Y + sin(random(360) * circle.width/2)];

    My wish is that the objects are all created at a random place, within the circle, not overlapping the outside of this circle.

    This did not work for me.

    Do you have another suggestion?

    I think I am looking for a way to spawn objects at an x distance pixels from the middle of a circle.

    If I worked with a square, this would have been no problem.

    Circles provide more complexity.

  • Hi Shadowdawnz - it's no problem replying to old posts because the discussion is often useful to someone else who finds the threads much later on.

  • hi,

    I tried:

    Every 0,1 seconds:

    Create object on (circle.X + cos(random(360) * circle.width/2), circle.Y + sin(random(360) * circle.width/2)];

    My wish is that the objects are all created at a random place, within the circle, not overlapping the outside of this circle.

    This did not work for me.

    Do you have another suggestion?

    I think I am looking for a way to spawn objects at an x distance pixels from the middle of a circle.

    If I worked with a square, this would have been no problem.

    Circles provide more complexity.

    I didnt not try with circles, only with squares.

    Unfortunately, my math is limited at this point in time.

    Hi Shadowdawnz - it's no problem replying to old posts because the discussion is often useful to someone else who finds the threads much later on.

    That is true.

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