Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SalahChafaiGameDesigner · Aug 29, 2018 at 10:52 AM · spawnsphere

Spawn Objects around a sphere

i want a script that spawn objects around a sphere

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eses · Aug 29, 2018 at 11:03 AM 2
Share

Hi @SalahChafaiGameDesigner


Your question is pretty vague.

How do you want your objects spawned? On random locations or in some specific patterns perhaps?

You say you need some free advice, but you don't pretty much even define what you need.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dan_wipf · Aug 29, 2018 at 11:04 AM

http://bfy.tw/JdB6 have a look at the link...


  using UnityEngine;
  using System.Collections;
  
  public class Example : MonoBehaviour {
  
      public int numObjects = 10;
      public GameObject prefab;
  
      void Start() {
          Vector3 center = transform.position;
          for (int i = 0; i < numObjects; i++){
              Vector3 pos = RandomCircle(center, 5.0f);
              Quaternion rot = Quaternion.FromToRotation(Vector3.forward, center-pos);
              Instantiate(prefab, pos, rot);
          }
      }
  
      Vector3 RandomCircle ( Vector3 center ,   float radius  ){
          float ang = Random.value * 360;
          Vector3 pos;
          pos.x = center.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad);
          pos.y = center.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad);
          pos.z = center.z;
          return pos;
      }
  }
 
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eses · Aug 29, 2018 at 01:17 PM 2
Share

@dan_wipf - plus 1 for the link. Good percent of questions here are lmgtfy category. In this day and age, I wonder how search engine isn't obvious first place to everyone when you have a question.

avatar image dan_wipf eses · Aug 29, 2018 at 01:22 PM 2
Share

that’s so true! alot of questions are com$$anonymous$$g up too much in a short period, and are answered a hundred times..

avatar image sacredgeometry eses · Jan 27, 2020 at 08:07 AM 0
Share

100%. Google is like having a friend that has all of human knowledge in his head and all you need to do is ask them the right question and you always get an instant reply.

The fact that people obviously dont use it is terrifying to me. In some forums just to make the point I have often just copied and pasted their question into google and linked to or quoted the literal first search result to show them how silly it is.

avatar image eses · Aug 29, 2018 at 01:21 PM 1
Share

I'll add a variant - without sin and cos (and transform position should be added to final position, it's missing here):

 public SphereCollider sphereCol;
 public GameObject spawned;
 
 void Start () 
 {
     var r = sphereCol.radius;
     
     for (int i = 0; i < 100; i++)
     {
         var spawned = Instantiate(this.spawned) as GameObject;
         
         var x = Random.Range(-1f,1f);
         var y = Random.Range(-1f,1f);
         var z = Random.Range(-1f,1f);
 
         var vec = new Vector3(x,y,z).normalized * r;
         spawned.transform.position = vec;
     }
 }
avatar image EnishanTopuz · Nov 14, 2021 at 12:47 AM 0
Share

is there a method to make it so they each spawn maybe 1 by 1 every 5 or so seconds?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawn Random Objects on a Sphere Surface 0 Answers

Sphere spawn from border in direction (2D) 0 Answers

Projecting a plane onto a sphere 2 Answers

overlap half sphere? 0 Answers

Find out 3D position of point on texture 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges