Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 cw4ed6 · Oct 12, 2012 at 06:35 PM · gravityspawndraginstantiationclones

Trouble spawning cloned objects

I am attempting to have objects spawn in one of four locations horizontally and then have gravity take effect and allow them to fall towards baskets located in corresponding locations on the ground.

I have placed the four original objects at the top of the screen in the four spawn locations and am attempting to randomise which of the four spawn locations is used, every four seconds. These original objects are being used as spawn points so that the duplicate objects will appear in the same location and fall from there. They have been set to kinematic (to allow the clones to appear through them), gravity is false (to avoid them falling) and their sphere colliders are disabled. I am attempting to change these settings in the code once the clone objects have been instantiated.

However, having attempted to code this in C#, I am finding that the objects never seem to spawn in. Can anyone offer some advice on this? Please note that the item prefabs are stored in the resources folder. Here is the code in the update method:

     // Update is called once per frame
     void Update () {
         
         
         GameObject ItemClone1;
         GameObject ItemClone2;
         GameObject ItemClone3;
         GameObject ItemClone4;
         
         
         //Create a timer, starting on 0
         double timer = 0.0;
         //Increase the timer in real time
         timer += Time.deltaTime;
         
         
         //Sets the condition if the number of seconds divided by 4 leaves a remainder of 0
         //In other words every 4 seconds
         if(timer % 4 == 0)
         {
         
             //Generate a random number between 1 and 4
             int spawnLocation = Random.Range(1,4);
         
             //Determine the spawn position based on the random number    
             if(spawnLocation == 1)
             {
                 ItemClone1 = (GameObject)Instantiate(Resources.Load("ItemPrefab1"));
                 ItemClone1.AddComponent("Rigidbody");
                 ItemClone1.rigidbody.useGravity = true;
                 ItemClone1.rigidbody.drag = 10.0F;
                 ItemClone1.rigidbody.isKinematic = true;
             }
         
             if(spawnLocation == 2)
             {
                 ItemClone2 = (GameObject)Instantiate(Resources.Load("ItemPrefab2"));
                 ItemClone2.AddComponent("Rigidbody");
                 ItemClone2.rigidbody.useGravity = true;
                 ItemClone2.rigidbody.drag = 10.0F;
                 ItemClone2.rigidbody.isKinematic = true;
             }
         
             if(spawnLocation == 3)
             {
                 ItemClone3 = (GameObject)Instantiate(Resources.Load("ItemPrefab3"));
                 ItemClone3.AddComponent("Rigidbody");
                 ItemClone3.rigidbody.useGravity = true;
                 ItemClone3.rigidbody.drag = 10.0F;
                 ItemClone3.rigidbody.isKinematic = true;
             }
         
             if(spawnLocation == 4)
             {
                 ItemClone4 = (GameObject)Instantiate(Resources.Load("ItemPrefab4"));
                 ItemClone4.AddComponent("Rigidbody");
                 ItemClone4.rigidbody.useGravity = true;
                 ItemClone4.rigidbody.drag = 10.0F;
                 ItemClone4.rigidbody.isKinematic = true;
             }
             
         }
 
     }
Comment
Add comment
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

1 Reply

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

Answer by sparkzbarca · Oct 12, 2012 at 07:08 PM

when you play and it "spawns" see if an object is added to the hierarchy off to the bottom left. if it is its spawning.

Now my guess is that the problem is IsKinematic doesnt actually stop it from messing with other objects movement and the object is in fact stuck inside the other. If thats true what you should be able to do is see that by.

 1. seeing a new object generated. 
 2. pausing the game 
 3. seeing the position of the clone is identical to where it should be
 4. moving the position of the base spawn object and unpausing and now seeing the object drop.

the solution if this is the case.

 1.Create an empty game object at all 4 locations exactly at where the CENTER of the spawned object should be.
 2. use  Instantiate (original : Object, position : Vector3, rotation : Quaternion) so
 Instaniate(SpawnObject,Empty_Game_Object_Spawn_Point.position, Empty_Game_Object_Spawn_Point.rotation);

hope that helps

Comment
Add comment · 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

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

10 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

Related Questions

How to get movable/pushable cubes right? 0 Answers

change gravity after time 1 Answer

My Objects all fall Unrealistically SLow with the deafult Gravity Even with Drag ZERO, what to do? 1 Answer

Respawning with no gravity 3 Answers

How to get drag to affect an aircraft velocity but not the gravity of the aircraft? 0 Answers


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