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 Reefer · Oct 11, 2013 at 03:00 PM · ballstucksideways

Ball getting stuck on going sideways.

My ball is getting stuck on going sideways quite often, I'm wondering which would be best way to fix this:

alt text

It just keeps going from one side to other.

So would the best way to prevent this from happening be that I apply little bit force for down all the time?

untitled-2.png (82.3 kB)
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 robertbu · Oct 11, 2013 at 04:35 PM

Without playing the game, it is hard to figure out what solution will look the best. I'm assuming you are playing on the XY plane. Start with something like this on the ball:

 if (Mathf.Abs(rigidbody.velocity.normalized.x) > 0.99) {
     rigidbody.AddForce(Vector3.up * Mathf.Sign(rigidbody.velocity.y) * someSmallValue);
 }

You may need to adjust the 0.99 value. You may only want to make this correction when you detect a collision with the wall. There are other ways to fix this problem if this one is not right.

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 Reefer · Oct 11, 2013 at 05:17 PM 0
Share

This works perfect, thank you.

I got one question still, what's wrong with this script:

     void OnCollisionEnter ( Collision col ) {
         hitPoints--;
         if ( hitPoints <= 0 ) {
             Die();
         }
         if (col.gameObject.tag == "Ball")
             Debug.Log ("Particles!");
         Instantiate(particlesPrefab, transform.position, Quaternion.identity);
         Destroy (gameObject);
     }

As it won't delete those particle systems that it instantiates.

avatar image robertbu · Oct 11, 2013 at 05:36 PM 1
Share

I would have to see more code. Nothing here destroys the particle system, so I'm not sure how you want this to be have. In addition since you do a Destory(gameObject), you are destroying this script, so any later code that would have destroyed the particle system won't be run . Often this kind of problem is handled by doing:

 GameObject go =  Instantiate(particlesPrefab, transform.position, Quaternion.identity) as GameObject;
 Destory(go, 2.5f);

This will destroy the particle system 2.5 seconds after the Destory() call.

Note it is best to ask new, unrelated questions as a new Unity Answers question. It is the way UA is designed, and you will have a much greater chance of getting an answer.

avatar image Reefer · Oct 11, 2013 at 05:59 PM 0
Share

I thought that was going to be a simple problem so didnt make a new question for it but no.. Now it gives me:

"Cannot implicitly convert type 'UnityEngine.Object' to 'UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)

"The best overloaded method match for 'UnityEngine.Object.Destroy(UnityEngine.Object, float)' has some invalid arguments"

"Argument '#2' cannot convert 'double' expression to type 'float'"

Here's the full code:

 using UnityEngine;
 using System.Collections;
 
 public class BrickScript : $$anonymous$$onoBehaviour {
     
     static int numBricks = 0;
     public int pointValue = 1;
     public int currentLvl = 0;
     public int hitPoints = 1;
     public int powerUpChance = 3;
     
     public Transform particlesPrefab;
     
     public GameObject[] powerUpPrefabs;
     
     public AudioClip[] hitaudio;
     
     // Use this for initialization
     void Start () {
         numBricks++;
     }
     
     // Update is called once per frame
     void Update () {
     if ( currentLvl == 4) {
             Application.LoadLevel("GameOver");
         }
 
     }
     
     void OnCollisionEnter ( Collision col ) {
         hitPoints--;
         if ( hitPoints <= 0 ) {
             Die();
         }
         if (col.gameObject.tag == "Ball")
             Debug.Log ("Particles!");
        GameObject go = Instantiate(particlesPrefab, transform.position, Quaternion.identity);
         Destroy (go, 2.5);
     }
     
     void Die() {
     Destroy ( gameObject );
         BallScript ball1Script= GameObject.FindGameObjectWithTag ("Ball").GetComponent<BallScript>();
         PaddleScript paddleScript= GameObject.Find ("Paddle").GetComponent<PaddleScript>();
         paddleScript.AddPoint(pointValue * (int)ball1Script.curspeed);
         
         numBricks--;
         
         Debug.Log (numBricks);
         
         if ( Random.Range(0, powerUpChance) == 0 ) {
         Instantiate( powerUpPrefabs[ Random.Range(0, powerUpPrefabs.Length) ] , transform.position, Quaternion.identity );
          }
         
         if ( numBricks <= 0 ) {
             //Load Next Level
         Application.LoadLevel(currentLvl+1);
         if(currentLvl == 1){
         GJAPIHelper.Trophies.ShowTrophyUnlockNotification (4086);
         }
         if(currentLvl == 2){
         GJAPIHelper.Trophies.ShowTrophyUnlockNotification (4087);
         }
         }
     }
 }
avatar image robertbu · Oct 11, 2013 at 06:55 PM 0
Share

Sorry, I forgot a cast. You need "as GameObject" on the end of the Instantiate. I've edited my comment.

avatar image Reefer · Oct 11, 2013 at 07:42 PM 0
Share

Changes you made gives errors:

"The best overloaded mathod match for 'UnityEngine.Object.Destroy(UnityEngine.Object, float)' has some invalid arguments"

"Argument '#2' cannot convert 'double' expression to type 'float'"

Show more comments

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 do i stop a ball from getting stuck? 3 Answers

how perevent ball from stuck in corner ? 0 Answers

Rolling ball gets stuck in corners 1 Answer

Player Camera Spline messes up camera direction 0 Answers

Unity stuck at "Creating APK package" 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