• 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 VAN-D00M · Jul 30, 2014 at 09:28 AM · instantiateyaxis

Done Something Wrong, Don't Know What I've Done?

Hi

I've got my asteroid, when i shoot it it should be destroyed and instantiate 4 more in its place. To do that I have created 4 empty game objects around my asteroid to spawn the others. I'm only using the X and Z axis as it is top down so they should spawn at 0 on the Y.

I was trying to make the asteroids bounce of other objects so I added a bouncy physic material. Next thing I know the asteroids instantiate all over the y axis? I froze position on the Y axis in rigidbody and took bouncy off but its still doing it. All spawn points are at 0 on the Y yet the asteroids instantiate off of 0 which they didn't before?

Any ideas what I could have done?

EDIT I've taken the code that deals and may affect with the instantiation issue. Asteroid Controller deals with instantiating.

The spawnUpper and spawnLower etc is looking top down so it differs on the X rather than on the Y. If that makes sense.

         public GameObject mAsteroid1;
     
         public Transform spawnUpper;
         public Transform spawnLower;
         public Transform spawnLeft;
         public Transform spawnRight;
     
     
         void OnTriggerEnter (Collider other)
         {
 
             Destroy (other.gameObject);
             Destroy (gameObject);
     
             Instantiate(mAsteroid1, spawnUpper.position, transform.rotation);
             Instantiate(mAsteroid1, spawnLower.position, transform.rotation);
             Instantiate(mAsteroid1, spawnLeft.position, transform.rotation);
             Instantiate(mAsteroid1, spawnRight.position, transform.rotation);
         }
     
 


Asteroid Mover

 void Start ()
     {
 
         //random rotator
         rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
 
         //movement
         Vector3 randomDirection = new Vector3(Random.Range(-1, 1), 0.0f, Random.Range(-1, 1));
         rigidbody.velocity = randomDirection * speed;
     }
 
Comment
Add comment · Show 2
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 meat5000 ♦ · Jul 30, 2014 at 09:29 AM 0
Share

Neeeeeed Cooooooode

avatar image markzareal · Jul 30, 2014 at 09:35 AM 0
Share

edit the discription and add your code in it. we can't answer you without knowing what the code is

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Arcadewiz · Jul 30, 2014 at 09:39 AM

Without code its a bit of a chore to understand whats going on ...

You can try one thing :

  1. In the game view Unselect Maximise on Play.

  2. Then run your scene and when the wrong kinds of object instantiate

  3. Press the pause button.

  4. Select the initialised game objects by selecting them in hierarchy view on the left panel.

  5. Check the properties of the new instantiated game objects and you might be able to trace whats gone wrong.

  6. Then you can also disable renderers selectively is there are too many object.

  7. You can always pause and modify on runtime till the point you discover where you went wrong.

Hope this helps.

Comment
Add comment · Show 8 · 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 VAN-D00M · Jul 30, 2014 at 09:48 AM 0
Share

I've done what you've suggested, and they seem to be actually spawning above/below the spawn points I've made. Since I put bouncy material on, I've had to freeze the Y position on the rigidbody to keep the first asteroid on 0. When the others instantiate, without freezing the Y they go all over, by freezing the Y they are trapped on the Y axis value they spawned at which isn't 0.

To me it looks like Bouncy screwed things up but I can't see how it has, even if I take Bouncy off its the same result.

avatar image Arcadewiz · Jul 30, 2014 at 10:01 AM 0
Share

Did you remove the "bounce" component or disable it from the source of your instantiation. If it is being instantiated from a prefab in project, you need to modify it there. Your instantiation code needs to be checked.

avatar image VAN-D00M · Jul 30, 2014 at 10:23 AM 0
Share

Just posted the code. I have been removing it from the Collider in the prefab itself. It doesn't seem to make a difference though.

avatar image Arcadewiz · Jul 30, 2014 at 10:49 AM 0
Share

Do your instantiated objects at run-time show "bounce" physics material in their collider ?

avatar image VAN-D00M · Jul 30, 2014 at 12:24 PM 0
Share

Yes they do.

Show more comments
avatar image
0

Answer by VAN-D00M · Jul 30, 2014 at 12:50 PM

I worked out whats gone wrong. The spawn points seem to be rotation with the asteroid meaning the spawn points are changing regarding the Y axis. Don't know why its doing that as it wasn't before so I've just got to work out how to stop those rotating but still following the asteroid.

[1]: /storage/temp/30057-screen+shot+2014-07-30+at+13.45.01.png


screen shot 2014-07-30 at 13.45.01.png (104.1 kB)
Comment
Add comment · Show 2 · 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 Arcadewiz · Jul 30, 2014 at 01:01 PM 0
Share

Comment out this in your code and try running:

rigidbody.angularVelocity = Random.insideUnitSphere * tumble;

avatar image VAN-D00M · Jul 30, 2014 at 01:39 PM 0
Share

That does it but it stops my asteroid tumbling about. If I was to fiddle with the parent and child objects something like that could work?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Y value wont work? 1 Answer

NullReferenceException: I think unity bug 3 Answers

Javascript code not working plz help 1 Answer

Static variables 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