• News

• Industries

• Learning & Support

• Community

• Marketplace

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

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!

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:confused:

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.

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.

Thanks Veovis, that sounds like it will work

Thanks timconwell , another great idea. I’ll let you know how it comes out

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.

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.

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.

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.