Announcement

Collapse
No announcement yet.

Spawn Within Circular Band

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Spawn Within Circular Band

    Hi,

    I'm unsure how to go about this, perhaps you guys can point me in the right direction.

    Basically, what I'm looking to do is spawn a bunch of asteroids randomly in a circular band with an adjustable max/min radius.

    Easy enough doing it along say, the X and Z axis as I just gotta check if it's within Xmin and Xmax or radiusMin/Max along said axis and then add/sub a random number between 0 and 25 for some height variance, but going in the circle is different, and I need some help.
    YouTube Playlist of W.I.P game project - https://www.youtube.com/playlist?lis...XCXMLFckHVo_bV (May contain swearing, I'm Irish :P)

    #2
    Originally posted by bogieman987 View Post
    Hi,

    I'm unsure how to go about this, perhaps you guys can point me in the right direction.

    Basically, what I'm looking to do is spawn a bunch of asteroids randomly in a circular band with an adjustable max/min radius.

    Easy enough doing it along say, the X and Z axis as I just gotta check if it's within Xmin and Xmax or radiusMin/Max along said axis and then add/sub a random number between 0 and 25 for some height variance, but going in the circle is different, and I need some help.
    There is the node 'get vector length', you could generate random spawn locations based on it being in a square, and then just subtract the location with the middle of the circle location (and plug the result into 'Get Vector Length'), and if it is greater than the circle's radius, find a new location.
    Marketplace Assets

    Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
    Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
    Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

    Comment


      #3
      That's relying on a lot of luck seeing as the square would be rather big and the asteroids are fairly small, could make the times generation times terrible and I don't really fancy sitting for several minutes for it to get it right as there will be a lot of em. And to do that every time something changes (in the editor).

      It's worth a try, though, perhaps it won't be too bad.
      Last edited by bogieman987; 06-23-2015, 04:51 AM.
      YouTube Playlist of W.I.P game project - https://www.youtube.com/playlist?lis...XCXMLFckHVo_bV (May contain swearing, I'm Irish :P)

      Comment


        #4
        What comes to mind would be making a vector along the x axis say, which definitely falls in your band (maybe using 'random float in range' with your min and max values). Then you could rotate that vector by a random number of degrees between 0 and 360 (although that might be doubling up the intial position since 0 and 360 give you the same position) to get somewhere random along the band.

        Comment


          #5
          I managed to get something working, rather nicely too I think.
          Basically, what I do is rotate a vector whose length is 1 to a random value between 0 and 360. Then I multiply that by a random number between the min and max radius, and add a random min and max height to the Z axis.
          Click image for larger version

Name:	1.png
Views:	1
Size:	161.7 KB
ID:	1080343

          Now my main problem is performance
          Last edited by bogieman987; 06-23-2015, 07:21 AM.
          YouTube Playlist of W.I.P game project - https://www.youtube.com/playlist?lis...XCXMLFckHVo_bV (May contain swearing, I'm Irish :P)

          Comment


            #6
            One could say you're reinventing the wheel. How about this?

            Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	66.6 KB
ID:	1080384

            The range should be 0-360 in your case, ofc.
            Last edited by Everynone; 06-23-2015, 04:40 PM.

            Comment


              #7
              Originally posted by Everynone View Post
              One could say you're reinventing the wheel. How about this?

              [ATTACH=CONFIG]44896[/ATTACH]

              The range should be 0-360 in your case, ofc.
              Why 360 rather than 359? 360 would be a duplicate possibility in case of 0 being a possibility.
              Marketplace Assets

              Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
              Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
              Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

              Comment


                #8
                Originally posted by Everynone View Post
                One could say you're reinventing the wheel. How about this?

                [ATTACH=CONFIG]44896[/ATTACH]

                The range should be 0-360 in your case, ofc.
                That would have been easier lol, need to learn more math :/
                Also, would it be better to use the degrees variants of sin and cos?
                YouTube Playlist of W.I.P game project - https://www.youtube.com/playlist?lis...XCXMLFckHVo_bV (May contain swearing, I'm Irish :P)

                Comment


                  #9
                  Just out of curiosity, as I'm feeling dumb: why use sine and cosine functions?
                  [On Hold]WIP: Vertex-Based Ledge Detection/Parkour Engine

                  Looking for fellow programmers to develop a project.

                  Comment


                    #10
                    We're looking for a point on the circumference. I'm pretty sure more than one method exists, like bogieman987 displayed above. In my head x = cos(angle) * radius gets you there.
                    I guess you could attach a springarm component and rotate it, it would involve vector transformation - not sure how efficient it is from the performance point of view, though. Negligible in some cases, critical in others.

                    @Horus: I doubt you're feeling dumb, you have something on your mind. How would you approach it?

                    @Jamendxman3: 0-359 will not give you 359.5, for example. And the chances of rolling precisely 0 and 360 with floats are pretty slim.

                    Comment

                    Working...
                    X