- Home /
Circle inside Circle
Hi, i really need some help here, im just working on a game prototype where i must randomly select a location. i got 2 circle in a same position but different radius. let says circle A (the orange circle) and circle B(blue circle). circle A is bigger than circle B. the problem is, how can i get a position where is inside circle A but outside the B circle here an example image
You mean, when some other object is inside orange circle but outside blue circle?
Answer by Hellium · Dec 19, 2018 at 11:30 AM
public Vector2 GetRandomPositionInside2DTorus( Vector2 center, float innerRadius, float outerRadius )
{
float angle = Random.value * Mathf.PI * 2;
return center + new Vector2( Mathf.Cos( angle ), Mathf.Sin( angle ) ) * Random.Range( innerRadius, outerRadius );
}
I forgot something in the formula to compute the angle:
float angle = Random.value * $$anonymous$$athf.PI;
should be
float angle = Random.value * $$anonymous$$athf.PI * 2;
Your answer
Follow this Question
Related Questions
2D Background Stop Moving on BoundingBox Exit? 2 Answers
UnityEngine.Component:get_transform() Error 1 Answer
Vector3 not receiving coordinates 1 Answer
Spawn object at a random predeterminated(transform) position 1 Answer
I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers