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 DadPool · Jan 31, 2015 at 03:06 AM · c#collisionphysicsobjectdestroy object

Unity's Breakout Tutorial Ball Issue.

I went through the Unity Tutorial for Creating a Breakout Game. I have two issues. First is that when the ball passes through the Death Zone at the bottom of the play field it never gets destroyed. I've tried a few things but always end up with two balls falling through empty space by the time I get to life three. And the second one is that the Ball sometime drifts enough on the Z axis to fall out of the screen. (Most likely due to the custom oval shaped paddle I have created to make it easier to pop the ball up into the play field when it starts bouncing almost perfectly Horizontal.) the temporary solution I have created is to create two solid cubes that are transparent to keep the ball true. But occasionally it still differs by .019 on the Z and it causes the ball to become extremely slow and sometime stop eventually when it hits the paddle and wall at the same time. I'm using the standard programming for the game that is in the unity Tutorial. I have checked it multiple times and can't find anything that I may have missed. I'm sure that I caused the problem with the new paddle and my Improvised restraints. IS there and easy fix for these?

Comment
Add comment · Show 8
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 ♦ · Jan 31, 2015 at 02:41 AM 1
Share

We would need to see some code. Your wall of text is a little tricky to get anything useful from :)

avatar image DadPool · Jan 31, 2015 at 02:59 AM 0
Share

I do over explain a bit sorry. Here is the Ball section

 using UnityEngine;
 using System.Collections;
 
 public class Ball : $$anonymous$$onoBehaviour {
 
     public float ballInitialVelocity = 600.0f;
     private Rigidbody rb;
     private bool ballInPlay;
     // Use this for initialization
     void Awake () {
         rb = GetComponent<Rigidbody>();
     
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (Input.GetButtonDown("Fire1") && ballInPlay == false)
         {
             transform.parent = null;
             ballInPlay = true;
             rb.is$$anonymous$$inematic = false;
             rb.AddForce(new Vector3(ballInitialVelocity, ballInitialVelocity, 0));
 
         }
         }
 
 }

avatar image DadPool · Jan 31, 2015 at 03:00 AM 0
Share

The G$$anonymous$$.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class G$$anonymous$$ : $$anonymous$$onoBehaviour
 {
     public int lives = 3;
     public int bricks = 20;
     public int score = 0;
     public float resetDelay = 1.0f;
     public Text livesText;
     public Text scoreText;
     public GameObject gameOver;
     public GameObject youWon;
     public GameObject bricksPrefab;
     public GameObject paddle;
     public GameObject deathParticles;
     public static G$$anonymous$$ instance = null;
     private GameObject clonePaddle;
     // Use this for initialization
     void Awake ()
     {
         if (instance == null)
             instance = this;
         else if (instance != null)
             Destroy (gameObject);    
         Setup ();
     }
 
     public void Setup ()
     {
         clonePaddle = Instantiate (paddle, transform.position, Quaternion.identity) as GameObject;
         Instantiate (bricksPrefab, transform.position, Quaternion.identity);
     }
 
     void CheckGameOver ()
     {
         if (bricks < 1) {
             youWon.SetActive (true);
             Time.timeScale = 0.25f;
             Invoke ("Reset", resetDelay);
         }
         if (lives < 1) {
             gameOver.SetActive (true);
             Time.timeScale = 0.25f;
             Invoke ("Reset", resetDelay);
         }
 
     }
 
     void Reset ()
     {
         Time.timeScale = 1.0f;
         Application.LoadLevel (Application.loadedLevel);
     }
 
     public void LoseLife ()
     {
         lives--;
         livesText.text = "Lives: " + lives;
         Instantiate (deathParticles, clonePaddle.transform.position, Quaternion.identity);
         Destroy (clonePaddle);
         Invoke ("SetupPaddle", resetDelay);
         CheckGameOver ();
     }
 
     void SetupPaddle ()
     {
         clonePaddle = Instantiate (paddle, transform.position, Quaternion.identity) as GameObject;
     }
 
     public void DestroyBrick ()
     {
         bricks--;
         score = score + 100;
         scoreText.text = "Score: " + score;
         CheckGameOver ();
     }
 }

avatar image meat5000 ♦ · Jan 31, 2015 at 03:01 AM 1
Share

G$$anonymous$$ needs reformatting :P

Highlight all the code and click the 101010 button.

avatar image DadPool · Jan 31, 2015 at 03:01 AM 0
Share

And the DeathZone

 using UnityEngine;
 using System.Collections;
 
 public class DeathZone : $$anonymous$$onoBehaviour {
 
     void OnTriggerEnter(Collider col)
     {
         G$$anonymous$$.instance.LoseLife();
 
     }
 }

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DadPool · Jan 31, 2015 at 07:03 AM

Well I fixed my own Issues. To lock the position of the Z travel for the ball. I just went into the inspector and check marked the Z constraint for the position. As far as the code I added a bit to the Ball code here is the new code.

 using UnityEngine;
 using System.Collections;
 
 public class Ball : MonoBehaviour
 {
 
     public float ballInitialVelocity = 600.0f;
     public GameObject floor;
     private Rigidbody rb;
     private bool ballInPlay;
     // Use this for initialization
     void Awake ()
     {
         rb = GetComponent<Rigidbody> ();
 
     
     }
     
     // Update is called once per frame
     void Update ()
     {
 
         if (Input.GetButtonDown ("Fire1") && ballInPlay == false) {
             transform.parent = null;
             ballInPlay = true;
             rb.isKinematic = false;
             rb.AddForce (new Vector3 (ballInitialVelocity, ballInitialVelocity, 0));
 
         }
 
 
     }
     void OnTriggerEnter (Collider floor)
     {
         Destroy (gameObject);
     }
 
 
 }

Now I don't have extra balls floating off into eternity while gameplay is going. I was also able to delete the two invisible barriers to lock in the ball to the play area.

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

20 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

Related Questions

FIXED: How can I stop a collider from tunneling? 2 Answers

Unity3D: Get Velocity after collision 0 Answers

Show trajectory path a ball will take based on collision 1 Answer

Optimize hundreds of objects 2 Answers

Manually check collision ? 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