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
2
Question by thekiwiflyer · Aug 16, 2014 at 08:16 PM · space shooterasteroid

Space Shooter: Asteroids not being destroyed

I haven't seen a solution for this yet so I'm hoping you guys can help me out. I have been going through the Unity Space Shooter tutorial and making good progress. I ran into a problem though at Step 11, Explosions. I continue to Step 13, Spawning Waves, hoping that the problem would resolve itself but nothing happened.

The asteroid that is created for the game reacts fine when it is in the hierarchy tabs, spawning and interacting with all objects as it should(being destroyed when it comes into contact with my ship, bolts or the game boundary). I've moved the asteroid into the prefab, it also worked as expected.

The problem happens when I go to the game controller and drag the drop the asteroid in the hazard tab. Once dropped in, the game plays and the hazard spawn but they do not interact, even with the game boundary and they continue to spawn and never leave the game. I have restarted unity, restarted my computer and replaced the code with the code at the bottom of the page. I'm not sure what is wrong and could use your help guys. I'll post the code bellow, thank you.

Destroy By Contact

 using UnityEngine;
 using System.Collections;
 
 public class DestroyByContact : MonoBehaviour
 {
     public GameObject explosion;
     public GameObject playerExplosion;
     
     void OnTriggerEnter(Collider other) 
     {
         if (other.tag == "Boundary")
         {
             return;
         }
         Instantiate(explosion, transform.position, transform.rotation);
         if (other.tag == "Player")
         {
             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
         }
         Destroy(other.gameObject);
         Destroy(gameObject);
     }
 }
 

Destroy By Boundary

 using UnityEngine;
 using System.Collections;
 
 public class DestroyByBoundary : MonoBehaviour
 {
     void OnTriggerExit(Collider other)
     {
         Destroy(other.gameObject);
     }
 }

Player Controller

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Boundary
 {
     public float xMin, xMax, zMin, zMax;
 }
 
 public class PlayerController : MonoBehaviour 
 {
     public float speed;
     public float tilt;
     public Boundary boundary;
 
     public GameObject shot;
     public Transform shotSpawn;
     public float fireRate;
 
     private float nextFire;
 
     void Update()
     {
         if (Input.GetButton("Fire1") && Time.time > nextFire) 
         {
             nextFire = Time.time + fireRate;
 //            GameObject clone = 
             Instantiate(shot, shotSpawn.position, shotSpawn.rotation); //as GameObject;
         }
     }
 
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
         rigidbody.velocity = movement * speed;
 
         rigidbody.position  = new Vector3
         (
             Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
             0.0f,
             Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
         );
         rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
     }
 }

Game Controller

 using UnityEngine;
 using System.Collections;
 
 public class GameController : MonoBehaviour
 {
     public GameObject hazard;
     public Vector3 spawnValues;
     public int hazardCount;
     public float spawnWait;
     public float startWait;
     public float waveWait;
     
     void Start ()
     {
         StartCoroutine (SpawnWaves ());
     }
     
     IEnumerator SpawnWaves ()
     {
         yield return new WaitForSeconds (startWait);
         while (true)
         {
             for (int i = 0; i < hazardCount; i++)
             {
                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                 Quaternion spawnRotation = Quaternion.identity;
                 Instantiate (hazard, spawnPosition, spawnRotation);
                 yield return new WaitForSeconds (spawnWait);
             }
             yield return new WaitForSeconds (waveWait);
         }
     }
 }

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
1

Answer by Waris Ali · Jun 11, 2015 at 09:16 AM

Remove the capsule collider from asteriod model child of GameObject Asteroid and give it to parent i.e. Asteroid (GameObject).

alt text

alt text


1.png (40.8 kB)
2.png (47.9 kB)
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

cannot show my hazard in space shooter 0 Answers

Creating a spread shot using prefabs 0 Answers

In the space shooter tutorial on the "creating shots" the bolt won't move 10 Answers

How do i change controller from keyboard to mouse?? 1 Answer

How to keep player in bounds? 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