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 *= 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

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

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.