ITeye博客

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

AVI · 2019-01-18 14:29 · Unreal · 行业应用 · Markdown

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?

 

 

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.

 

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.

 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。