0
\$\begingroup\$

First of all please note that the game is in 3d and Not 2d

The image below is seen from above. What I am trying to do is find a random point 2 - 3 meters around the player.

However I am not quite sure how to achieve it:

I have tried the following:

Vector3 randomPointOnCircle = Random.insideUnitSphere;
randomPointOnCircle.Normalize();
randomPointOnCircle *= radius;
return randomPointOnCircle;

However I am not sure how to set the player as the center?

enter image description here Star - Player

Square the general ground

Circle - A visual representation of where the points should be around the player

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Your current code selects a point on a sphere, not on a circle. Is that intentional? \$\endgroup\$
    – DMGregory
    Jun 10, 2020 at 17:53

1 Answer 1

1
\$\begingroup\$

This is a trivial application of the unit circle:

Vector3 RandomPointOnXZCircle(Vector3 center, float radius) {
    float angle = Random.Range(0, 2f * Mathf.PI);
    return center + new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .