Announcement

Collapse
No announcement yet.

Spawning randomly around edge of a circle and not in the center.

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

    Spawning randomly around edge of a circle and not in the center.

    I am trying to randomly spawn around the edge of a circle and not in the center of the circle?

    I am currently spawning with the following:
    Random X spawn 100 to -100
    Random Y spawn 100 to -100
    How do I eliminate the center red area from the equation?
    Attached Files
    My UE4 iOS Game
    https://itunes.apple.com/us/app/dan-...2570?ls=1&mt=8

    #2
    Hi Stache, try setting a branch where if your var is > |75|, do your function. Additionally, you could try providing a clamp with the min value as 75 and the max as 100. Try those and let me know if they work for you!
    Adam Davis | Marketplace Support | Epic Games
    How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

    Comment


      #3
      Thank you Adam. I am not able to test this now but I will tonight.
      Excuse me, if my artist logic is wrong but won't a branch and > eliminate half of the circle by ignoring the negative sides? I think it is the negative thing that makes my brain hurt
      My UE4 iOS Game
      https://itunes.apple.com/us/app/dan-...2570?ls=1&mt=8

      Comment


        #4
        That sounds more like a square than a circle.

        You might want to just get two random numbers, one from 75 to 100, and another from 0-359. Then use those values to determine the right place relative to the spawner origin.

        Comment


          #5
          Maybe a random rotation around a point, then add a magnitude between 75 and 100? Add that vector to the origin and should give you something in that circle.

          Comment


            #6
            Thanks Veovis, that sounds like it will work
            My UE4 iOS Game
            https://itunes.apple.com/us/app/dan-...2570?ls=1&mt=8

            Comment


              #7
              Thanks timconwell , another great idea. I'll let you know how it comes out
              My UE4 iOS Game
              https://itunes.apple.com/us/app/dan-...2570?ls=1&mt=8

              Comment


                #8
                seriously, even if we don't have sin/cos. you can still do this to land points on a circle.

                newP = oldP + normalize( vector2d( randomX, randomY)) * radius.

                you just have to be sure x/y are not both zero.

                with sin/cos you only need one random number and no worry about other situation.

                newP = oldP + vector2d( cos(randomDegree), sin(randomDegree)) * radius.
                Unreal Engine 4 Game Framework diagram for relation of all major base object types
                Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
                Resident Evil Classic Camera
                RPCs official document, Must Read
                Everything you should know about replication

                Comment


                  #9
                  Using some basic maths you could do this. Taking the equation for finding a point on the circumference of a circle you just sub the radius to be between your min and max area.

                  Click image for larger version

Name:	PointAroundTheEdgeOfACircle.png
Views:	1
Size:	132.2 KB
ID:	1056959
                  Check out my pet project: Salvos - Maze Survival

                  Looking for blueprint tutorials? Then visit my blog or YouTube channel.
                  Blog: voxagon Youtube: Click

                  Comment


                    #10
                    Maybe if you like math! Lol

                    An easier way is to "Get Random float in range" -180 to 180, Make Rot from it (using it as yaw), Get Rotation XVector, multiply that vector by another "Get Random Float in range" for the distance range, and then add that to the spawn location (either using Get Actor Location for the spawn station or whatever).

                    Same effect, but far fewer nodes and simpler to understand. It might incur a slight performance overhead but I can't imagine it'd be substantial enough for it to matter.

                    Comment


                      #11
                      Thanks to everyone for the great replies. It is working. Happy dance time.

                      pattm, extra thanks to you as your model seems more reliable than what RhythmScript proposed. RhythmScript's idea only worked about 9 out of 10 times and that could have been due an error on my end as I tend make a lot.
                      My UE4 iOS Game
                      https://itunes.apple.com/us/app/dan-...2570?ls=1&mt=8

                      Comment

                      Working...
                      X