E
E
Emil2019-11-05 23:33:44
C++ / C#
Emil, 2019-11-05 23:33:44

How to spawn an object within a radius of a certain sphere?

Hello, tell me please. How to spawn an object with a random position in a spherical 2D zone.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Griboks, 2019-11-06
@Griboks

I heard somewhere that the unit has a site with documentation. It must have been stolen since you're asking this question. Luckily I still have the link: https://docs.unity3d.com/ScriptReference/Random-in...

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Sets the position to be somewhere inside a sphere
        // with radius 5 and the center at zero.

        transform.position = Random.insideUnitSphere * 5;
    }
}

N
nuclear_kote, 2019-11-06
@nuclear_kote

You take a spawn point, and along two axes you randomize within a certain limit. Roughly speaking, from -1 to 1 in x, y. z = z spawn points

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question