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 zBlanco · Aug 05, 2013 at 03:09 AM · c#instantiatespawnspawning

Instantiate is throwing my throwing my objects?

So I'm creating a spawning script to spawn my AI using Instantiate. I'm passing the spawner's location and rotation and the game object I want to have spawned. The script works perfectly except that for some reason when the object is instantiated, it is thrown at about 200 meters/second and I have no idea how to fix it. because when I set the vector3 position as 0, 0, 0 it works perfectly fine, but once the location is moved from the origin, the object it actually thrown at that vector. I'm extremely confused.

Here's the sample of code where I instantiate the the new objects. I'm basically trying to instantiate them at the spawner's position.

easyAI, mediumAI, and toughAI are all primitive GameObjects with an attached rigidbody purely used for testing.

 private void spawn(int spawnNum){
         if(spawnNum < chanceEasy){
             Instantiate(easyAI, gameObject.transform.position, gameObject.transform.rotation);
             n_AI++;
             lastSpawnTime = Time.time;
             spawnTime = r.Next(minWait, maxWait);
             spawnChance = r.Next(0, 100);
         }else if(spawnNum > chanceEasy && spawnNum < (100 - chanceTough)){
             Instantiate(mediumAI, gameObject.transform.position, gameObject.transform.rotation);
             n_AI++;
             lastSpawnTime = Time.time;
             spawnTime = r.Next(minWait, maxWait);
             spawnChance = r.Next(0, 100);
         }else if(spawnNum > (100-chanceTough)){
             Instantiate(toughAI, gameObject.transform.position, gameObject.transform.rotation);
             n_AI++;
             lastSpawnTime = Time.time;
             spawnTime = r.Next(minWait, maxWait);
             spawnChance = r.Next(0, 100);
         }else {
             Debug.Log("Error, Spawn Number Out of range");
             
         }
             
         }

If anyone could offer any insight to my problem it would be appreciated. I am baffled by what is going on. Thank you

Comment
Add comment · Show 5
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 zBlanco · Aug 05, 2013 at 03:21 AM 0
Share

well I removed the rigidbody from each object and they seem to be spawning in the correct location. So I guess it has to do with the rigidbodies.

avatar image voporak5 · Aug 05, 2013 at 03:24 AM 0
Share

Yeah, Unity has some weird stuff like that lol =p. $$anonymous$$y Instantiate problem was that when my object was spawning, the longer it spawned for the more it traveled down the Z axis away from the Spawn location I originally wanted due to my prefab not being 0'ed out.

avatar image zBlanco · Aug 05, 2013 at 03:30 AM 0
Share

well now what if I want the prefab to have a rigidbody and still spawn in the right location? What do you think I could do?

avatar image robertbu · Aug 05, 2013 at 03:33 AM 0
Share

Shot in the dark. If you are instantiating your objects from a scene object and not from a prefab, note that they will inherit all the properties of the object at the time of the instantiate. So if the object you are instantiating has a velocity, the instantiated object will as well. You can "fix" the problem by setting the velocity to zero.

avatar image voporak5 · Aug 05, 2013 at 04:10 AM 0
Share

@ zBlanco Idk, I'm trying to avoid Rigidbodies & movement until I understand physics better

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by voporak5 · Aug 05, 2013 at 03:19 AM

Idk if this will help but 1, is your prefabs' locations set to 0,0,0 and also do they have a rigidbody? I know somethings if you throw a rigidbody on they do weird stuff like try throwing it onto your Main Camera and the Camera will just start floating up lol.

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

15 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

Related Questions

How to Spawn after checking if the clones are destroyed. 1 Answer

How Do I Add An Instantiated Object To An Array? 3 Answers

Enemy spawn, round based 1 Answer

Having Trouble with Instantiating an object on an axis 2 Answers

player spawning 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